0
@@ -25,19 +25,24 @@ module ActiveCouch
0
klass_atts = self.class.attributes
0
klass_assocs = self.class.associations
0
klass_callbacks = self.class.callbacks
0
# ActiveCouch::Connection object will be readable in every
0
# object instantiated from a subclass of ActiveCouch::Base
0
SPECIAL_MEMBERS.each do |k|
0
self.instance_eval "def #{k}; @#{k}; end"
0
- klass_atts.each_key do |k|
0
- @attributes[k] = klass_atts[k]
0
- self.instance_eval "def #{k}; attributes[:#{k}]; end"
0
- self.instance_eval "def #{k}=(val); attributes[:#{k}] = val; end"
0
+ # First, initialize all the attributes
0
+ klass_atts.each_key do |property|
0
+ @attributes[property] = klass_atts[property]
0
+ self.instance_eval "def #{property}; attributes[:#{property}]; end"
0
+ self.instance_eval "def #{property}=(val); attributes[:#{property}] = val; end"
0
+ # These are special attributes which need aliases (for now, it's _id and _rev)
0
+ if property.to_s[0,1] == '_'
0
+ aliased_prop = property.to_s.slice(1, property.to_s.size)
0
+ self.instance_eval "def #{aliased_prop}; self.#{property}; end"
0
+ self.instance_eval "def #{aliased_prop}=(val); self.#{property}=(val); end"
0
+
# Then, initialize all the associations0
klass_assocs.each_key do |k|
0
@associations[k] = klass_assocs[k]
0
self.instance_eval "def #{k}; @#{k} ||= []; end"
0
@@ -45,22 +50,13 @@ module ActiveCouch
0
# to the object instantiated from the class
0
self.instance_eval "def add_#{k.singularize}(val); @#{k} = #{k} << val; end"
0
+
# Finally, all the calbacks 0
klass_callbacks.each_key do |k|
0
@callbacks[k] = klass_callbacks[k].dup
0
- DEFAULT_ATTRIBUTES.each do |x|
0
- self.instance_eval "def #{x}; self._#{x}; end"
0
- self.instance_eval "def #{x}=(val); self._#{x}=(val); end"
0
# Set any instance variables if any, which are present in the params hash
0
- # Now you can do stuff like
0
+ # Handle the block, which can also be used to initialize the object
0
yield self if block_given?
Comments
No one has commented yet.