2009-02-09 20:20:23 +01:00
|
|
|
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={})
|
2009-04-02 16:00:28 +02:00
|
|
|
raise StandardError unless self.is_a? Hash
|
2009-05-27 03:27:49 +02:00
|
|
|
apply_defaults # defined in CouchRest::Mixins::Properties
|
2009-04-02 16:00:28 +02:00
|
|
|
super()
|
2009-02-09 20:20:23 +01:00
|
|
|
keys.each do |k,v|
|
|
|
|
self[k.to_s] = v
|
|
|
|
end if keys
|
2009-05-25 21:12:56 +02:00
|
|
|
cast_keys # defined in CouchRest::Mixins::Properties
|
2009-02-09 20:20:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def []= key, value
|
|
|
|
super(key.to_s, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def [] key
|
|
|
|
super(key.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|