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)
-
- (Object) name
Returns the value of attribute name.
-
- (Object) type
Returns the value of attribute type.
Instance Method Summary (collapse)
- - (Object) build(object, json)
- - (Boolean) dirty?(object)
-
- (SimpleProperty) initialize(owner_clazz, name, options = {})
constructor
A new instance of SimpleProperty.
- - (Object) serialize(json, object) (also: #value)
Constructor Details
- (SimpleProperty) initialize(owner_clazz, name, options = {})
A new instance of SimpleProperty
20 21 22 23 24 25 26 27 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 20 def initialize(owner_clazz, name, = {}) self.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
- (Object) name
Returns the value of attribute name
18 19 20 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 18 def name @name end |
- (Object) type
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
- (Object) build(object, json)
29 30 31 32 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 29 def build(object, json) value = json[name.to_s].nil? ? json[name.to_sym] : json[name.to_s] object.send "#{name}=", value end |
- (Boolean) dirty?(object)
34 35 36 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 34 def dirty?(object) object.send("#{name}_changed?") end |
- (Object) serialize(json, object) Also known as: value
38 39 40 |
# File 'lib/couch_potato/persistence/simple_property.rb', line 38 def serialize(json, object) json[name] = object.send name end |