Class: CouchPotato::Persistence::SimpleProperty
- Inherits:
-
Object
- Object
- CouchPotato::Persistence::SimpleProperty
- Defined in:
- lib/couch_potato/persistence/simple_property.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #build(object, json) ⇒ Object
- #destroy(object) ⇒ Object
- #dirty?(object) ⇒ Boolean
-
#initialize(owner_clazz, name, options = {}) ⇒ SimpleProperty
constructor
A new instance of SimpleProperty.
- #save(object) ⇒ Object
- #serialize(json, object) ⇒ Object
Constructor Details
#initialize(owner_clazz, name, options = {}) ⇒ SimpleProperty
Returns a new instance of SimpleProperty.
6 7 8 9 10 11 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 6 def initialize(owner_clazz, name, = {}) self.name = name self.type = [:type] define_accessors accessors_module_for(owner_clazz), name, end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 4 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 4 def type @type end |
Instance Method Details
#build(object, json) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 13 def build(object, json) value = json[name.to_s] || json[name.to_sym] typecast_value = if type type.json_create value else value end object.send "#{name}=", typecast_value end |
#destroy(object) ⇒ Object
31 32 33 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 31 def destroy(object) end |
#dirty?(object) ⇒ Boolean
23 24 25 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 23 def dirty?(object) object.send("#{name}_changed?") end |
#save(object) ⇒ Object
27 28 29 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 27 def save(object) end |
#serialize(json, object) ⇒ Object
35 36 37 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 35 def serialize(json, object) json[name] = object.send name end |