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

#lambda_context, #represented, #user_options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash::PropertyBinding

#deserialize_from, #read

Methods inherited from Binding

build, #compile_fragment, #definition, #deserialize, #get, #read_fragment, #read_fragment_for, #serialize, #set, #uncompile_fragment, #write_fragment, #write_fragment_for

Constructor Details

#initialize(*args) ⇒ PropertyBinding

FIXME. make generic.



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

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

Class Method Details

.build_for(definition, *args) ⇒ Object



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

def self.build_for(definition, *args)
  return CollectionBinding.new(definition, *args) if definition.array?
  new(definition, *args)
end

Instance Method Details

#serialize_for(value) ⇒ Object



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

def serialize_for(value)
  write_scalar serialize(value)
end

#write(map, value) ⇒ Object



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

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

#write_scalar(value) ⇒ Object



41
42
43
# File 'lib/representable/bindings/yaml_bindings.rb', line 41

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