Class: CouchPotato::Persistence::SimpleProperty

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SimpleProperty.



6
7
8
9
10
11
12
# File 'lib/couch_potato/persistence/simple_property.rb', line 6

def initialize(owner_clazz, name, options = {})
  self.name = name
  self.type = options[:type]
  @type_caster = TypeCaster.new
  
  define_accessors accessors_module_for(owner_clazz), name, options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/couch_potato/persistence/simple_property.rb', line 4

def name
  @name
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/couch_potato/persistence/simple_property.rb', line 4

def type
  @type
end

Instance Method Details

#build(object, json) ⇒ Object



14
15
16
17
# File 'lib/couch_potato/persistence/simple_property.rb', line 14

def build(object, json)
  value = json[name.to_s].nil? ? json[name.to_sym] : json[name.to_s]
  object.send "#{name}=", value
end

#dirty?(object) ⇒ Boolean

Returns:

  • (Boolean)


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

def dirty?(object)
  object.send("#{name}_changed?")
end

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



23
24
25
# File 'lib/couch_potato/persistence/simple_property.rb', line 23

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