Class: Representable::Hash::HashBinding

Inherits:
PropertyBinding 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 PropertyBinding

#initialize, #read, #write

Methods inherited from Binding

#deserialize, #initialize, #serialize

Constructor Details

This class inherits a constructor from Representable::Hash::PropertyBinding

Instance Method Details

#deserialize_from(fragment) ⇒ Object



64
65
66
# File 'lib/representable/bindings/hash_bindings.rb', line 64

def deserialize_from(fragment)
  fragment.each { |key, item_fragment| fragment[key] = deserialize(item_fragment) }
end

#serialize_for(value) ⇒ Object



57
58
59
60
61
62
# File 'lib/representable/bindings/hash_bindings.rb', line 57

def serialize_for(value)
  # requires value to respond to #each with two block parameters.
  {}.tap do |hash|
    value.each { |key, obj| hash[key] = serialize(obj) }
  end
end