Class: CouchPotato::Persistence::SimpleProperty
- Inherits:
-
Object
- Object
- CouchPotato::Persistence::SimpleProperty
- Defined in:
- lib/couch_potato/persistence/simple_property.rb
Overview
:nodoc:
Direct Known Subclasses
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
- #changed?(object) ⇒ Boolean
-
#initialize(owner_clazz, name, options = {}) ⇒ SimpleProperty
constructor
A new instance of SimpleProperty.
- #serialize(json, object) ⇒ Object (also: #value)
Constructor Details
#initialize(owner_clazz, name, options = {}) ⇒ SimpleProperty
Returns a new instance of SimpleProperty.
20 21 22 23 24 25 26 27 28 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 20 def initialize(owner_clazz, name, = {}) self.name = name @setter_name = "#{name}=" self.type = [:type] @type_caster = TypeCaster.new owner_clazz.send :include, PropertyMethods unless owner_clazz.ancestors.include?(PropertyMethods) define_accessors accessors_module_for(owner_clazz), name, end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
18 19 20 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 18 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
18 19 20 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 18 def type @type end |
Instance Method Details
#build(object, json) ⇒ Object
30 31 32 33 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 30 def build(object, json) value = json[name] object.send @setter_name, value end |
#changed?(object) ⇒ Boolean
35 36 37 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 35 def changed?(object) object.send("#{name}_changed?") end |
#serialize(json, object) ⇒ Object Also known as: value
39 40 41 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 39 def serialize(json, object) json[name] = @type_caster.cast_back object.send(name) end |