This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ofer@shinybox:~/src/mcbooks$ rake --trace | |
** Invoke default (first_time) | |
** Invoke spec (first_time) | |
** Execute spec | |
/home/ofer/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec ./spec/models/account_spec.rb | |
/home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/rspec-rails-2.11.0/lib/rspec/rails/extensions/active_record/base.rb:27:in `<top (required)>': uninitialized constant ActiveModel (NameError) | |
from /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/rspec-rails-2.11.0/lib/rspec/rails/extensions.rb:1:in `require' | |
from /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/rspec-rails-2.11.0/lib/rspec/rails/extensions.rb:1:in `<top (required)>' | |
from /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/rspec-rails-2.11.0/lib/rspec/rails.rb:8:in `require' | |
from /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/rspec-rails-2.11.0/lib/rspec/rails.rb:8:in `<top (required)>' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Ledger | |
class Base | |
include Mongoid::Document | |
field :currency, type: Symbol, default: Money.default_currency.id | |
validates :currency, presence: true, inclusion: {in: Money::Currency.table.keys} | |
def currency | |
Money::Currency.new(self[:currency]) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given: An Account model in the database with a :name field. A list of account objects with names like "Accounts Payable" which are human-readable. | |
Need to: Be able to reference specific accounts by name in your business logic. For example, let's say you define a method that records a petty cash expenditure: | |
def spend_petty_cash | |
Account.find('Petty Cash').credit(20) | |
Account.find('Expenses').debit(20) | |
end | |
It's error prone and inelegant to use human-readable strings directly in your code everywhere to identify an account (with capital letters, spaces, and who knows what else, since they're defined by the accountants, not programmers). So, it would be useful for this - and provide additional benefits - to have a config file with something like: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mongoid' | |
def ArrayOf(klass) | |
array_klass_name = "#{klass}Array" | |
array_klass = Object.const_set(array_klass_name.to_sym, Class.new(Array)) | |
array_klass.class_eval do | |
def self.demongoize(obj) | |
new(obj.map {|e| klass.demongoize(e)}) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mongoid | |
module Document | |
module ClassMethods | |
def HashOf(klass) | |
hash_klass_name = "#{klass}Hash" | |
hash_klass = Object.const_set(hash_klass_name.to_sym, Class.new(Hash)) | |
hash_klass.class_eval do | |
define_singleton_method(:demongoize) do |obj| | |
new( obj.merge(obj) { |k,v| k, klass.demongoize(v) } ) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Twilio Setup | |
var last_called = null; | |
var halt_auto_flag = false; | |
Twilio.Device.ready(function (device) { | |
$('#log').append("Ready; "); | |
}); | |
Twilio.Device.error(function (error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.store = DS.Store.create({ | |
adapter: DS.RESTAdapter.create({bulkCommit: false}), | |
revision: 4 | |
}); | |
App.Person = DS.Model.extend({ | |
name: DS.attr('string'), | |
address: DS.attr('string'), | |
phone: DS.attr('string'), | |
note: DS.attr('string'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
localhost:5000/lists/18 | |
{"people":[{"id":4,"name":"Ofer Nave","address":"Manchester, NH","phone":"6038512523","note":"this asshole is never home!","completed":false,"result":null,"last_called_at":"2012-09-15T18:44:24Z"},{"id":5,"name":"John Doe","address":"Somewhere, NH","phone":"6035555555","note":null,"completed":false,"result":null,"last_called_at":null},{"id":6,"name":"Another Ofer","address":"Dover, NH","phone":"3107212658","note":null,"completed":false,"result":null,"last_called_at":null}],"list":{"id":18,"name":"Free State Now","description":"Potential FSP signers -- MA.","created_at":"2012-09-04T04:03:40Z","updated_at":"2012-09-04T04:03:40Z","people":[4,5,6]}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ember.js Application Setup | |
var App = Ember.Application.create(); | |
App.ApplicationController = Ember.Controller.extend(); | |
App.ApplicationView = Ember.View.extend({ templateName: 'application' }); | |
App.store = DS.Store.create({ | |
// adapter: DS.RESTAdapter.create({bulkCommit: false}), | |
adapter: DS.FixtureAdapter.create(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if pickup | |
TWILIO REQUESTS | |
Voice URL | |
AnsweredBy 'human' | |
StatusCallback URL | |
CallStatus 'completed' | |
CALL RESOURCE | |
AnsweredBy 'human' | |
Status 'completed' |
OlderNewer