Class: SimplyCouch::Model::Persistence::SimpleProperty
- Inherits:
-
Object
- Object
- SimplyCouch::Model::Persistence::SimpleProperty
- Defined in:
- lib/simply_couch/model/persistence.rb
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.
152 153 154 155 156 157 158 159 |
# File 'lib/simply_couch/model/persistence.rb', line 152 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.
150 151 152 |
# File 'lib/simply_couch/model/persistence.rb', line 150 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
150 151 152 |
# File 'lib/simply_couch/model/persistence.rb', line 150 def type @type end |
Instance Method Details
#build(object, json) ⇒ Object
161 |
# File 'lib/simply_couch/model/persistence.rb', line 161 def build(object, json); object.public_send @setter_name, json[name]; end |
#changed?(object) ⇒ Boolean
162 |
# File 'lib/simply_couch/model/persistence.rb', line 162 def changed?(object); object.public_send("#{name}_changed?"); end |
#serialize(json, object) ⇒ Object Also known as: value
163 |
# File 'lib/simply_couch/model/persistence.rb', line 163 def serialize(json, object); json[name] = @type_caster.cast_back object.public_send(name); end |