Started working on casted models, basic functionalities are now in.
property :casted_attribute, :cast_as => 'WithCastedModelMixin' A casted attribute now knows about its parent. (#casted_by to retrieve the parent's object)
This commit is contained in:
parent
fa7b176fce
commit
621f5565e9
10 changed files with 177 additions and 40 deletions
28
lib/couchrest/more/casted_model.rb
Normal file
28
lib/couchrest/more/casted_model.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
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={})
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue