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
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #build(object, json) ⇒ Object
-
#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.
27 28 29 30 31 32 33 34 35 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 27 def initialize(owner_clazz, name, = {}) self.name = name self.type = [:type] self.default_value = [:default] @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
#default_value ⇒ Object
Returns the value of attribute default_value.
25 26 27 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 25 def default_value @default_value end |
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 25 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
25 26 27 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 25 def type @type end |
Instance Method Details
#build(object, json) ⇒ Object
37 38 39 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 37 def build(object, json) object.send(:assign_attribute, name, json[name], from_json: true) end |
#serialize(json, object) ⇒ Object Also known as: value
41 42 43 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 41 def serialize(json, object) json[name] = object.send name end |