Class: Representable::Hash::PropertyBinding

Inherits:
Binding
  • Object
show all
Defined in:
lib/representable/bindings/hash_bindings.rb

Instance Attribute Summary

Attributes inherited from Binding

#definition

Instance Method Summary collapse

Methods inherited from Binding

#deserialize, #serialize

Constructor Details

#initialize(definition) ⇒ PropertyBinding

FIXME. make generic.



19
20
21
22
# File 'lib/representable/bindings/hash_bindings.rb', line 19

def initialize(definition) # FIXME. make generic.
  super
  extend ObjectBinding if definition.typed?
end

Instance Method Details

#deserialize_from(fragment) ⇒ Object



39
40
41
# File 'lib/representable/bindings/hash_bindings.rb', line 39

def deserialize_from(fragment)
  deserialize(fragment)
end

#read(hash) ⇒ Object



24
25
26
27
28
29
# File 'lib/representable/bindings/hash_bindings.rb', line 24

def read(hash)
  return FragmentNotFound unless hash.has_key?(definition.from) # DISCUSS: put it all in #read for performance. not really sure if i like returning that special thing.
  
  fragment = hash[definition.from]
  deserialize_from(fragment)
end

#serialize_for(value) ⇒ Object



35
36
37
# File 'lib/representable/bindings/hash_bindings.rb', line 35

def serialize_for(value)
  serialize(value)
end

#write(hash, value) ⇒ Object



31
32
33
# File 'lib/representable/bindings/hash_bindings.rb', line 31

def write(hash, value)
  hash[definition.from] = serialize_for(value)
end