Class: Representable::YAML::PropertyBinding

Inherits:
Hash::PropertyBinding show all
Defined in:
lib/representable/bindings/yaml_bindings.rb

Direct Known Subclasses

CollectionBinding

Instance Attribute Summary

Attributes inherited from Binding

#definition

Instance Method Summary collapse

Methods inherited from Hash::PropertyBinding

#deserialize_from, #read

Methods inherited from Binding

#deserialize, #serialize

Constructor Details

#initialize(definition) ⇒ PropertyBinding

FIXME. make generic.



22
23
24
25
# File 'lib/representable/bindings/yaml_bindings.rb', line 22

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

Instance Method Details

#serialize_for(value) ⇒ Object



32
33
34
# File 'lib/representable/bindings/yaml_bindings.rb', line 32

def serialize_for(value)
  write_scalar serialize(value)
end

#write(map, value) ⇒ Object



27
28
29
30
# File 'lib/representable/bindings/yaml_bindings.rb', line 27

def write(map, value)
  map.children << Psych::Nodes::Scalar.new(definition.from)
  map.children << serialize_for(value)  # FIXME: should be serialize.
end

#write_scalar(value) ⇒ Object



36
37
38
# File 'lib/representable/bindings/yaml_bindings.rb', line 36

def write_scalar(value)
  Psych::Nodes::Scalar.new(value.to_s)
end