Class: CouchPotato::Persistence::SimpleProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/couch_potato/persistence/simple_property.rb

Overview

:nodoc:

Direct Known Subclasses

DeepTrackedProperty

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_clazz, name, options = {}) ⇒ SimpleProperty

Returns a new instance of SimpleProperty.



20
21
22
23
24
25
26
27
28
29
# File 'lib/couch_potato/persistence/simple_property.rb', line 20

def initialize(owner_clazz, name, options = {})
  self.name = name
  @setter_name = "#{name}="
  self.type = options[:type]
  self.default_value = options[:default]
  @type_caster = TypeCaster.new
  owner_clazz.send :include, PropertyMethods unless owner_clazz.ancestors.include?(PropertyMethods)

  define_accessors accessors_module_for(owner_clazz), name, options
end

Instance Attribute Details

#default_valueObject

Returns the value of attribute default_value.



18
19
20
# File 'lib/couch_potato/persistence/simple_property.rb', line 18

def default_value
  @default_value
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/couch_potato/persistence/simple_property.rb', line 18

def name
  @name
end

#typeObject

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



31
32
33
34
# File 'lib/couch_potato/persistence/simple_property.rb', line 31

def build(object, json)
  value = json[name]
  object.send @setter_name, value
end

#serialize(json, object) ⇒ Object Also known as: value



36
37
38
# File 'lib/couch_potato/persistence/simple_property.rb', line 36

def serialize(json, object)
  json[name] = object.send name
end