couchrest_model/lib/couchrest/more/casted_model.rb
YAMAMOTO Yohei 6fca60ebe4 fixed a bug with CastedModel constructer calling Hash#initialize(ifnone)
Signed-off-by: Matt Aimonetti <mattaimonetti@gmail.com>
2009-04-28 11:32:59 +08:00

29 lines
No EOL
679 B
Ruby

require File.join(File.dirname(__FILE__), '..', 'mixins', 'properties')
module CouchRest
module CastedModel
def self.included(base)
base.send(:include, CouchRest::Mixins::Properties)
base.send(:attr_accessor, :casted_by)
end
def initialize(keys={})
raise StandardError unless self.is_a? Hash
super()
keys.each do |k,v|
self[k.to_s] = v
end if keys
apply_defaults # defined in CouchRest::Mixins::Properties
# cast_keys # defined in CouchRest::Mixins::Properties
end
def []= key, value
super(key.to_s, value)
end
def [] key
super(key.to_s)
end
end
end