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

#represented, #user_options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash::PropertyBinding

#deserialize_from, #read

Methods included from Binding::Object

#create_object, #deserialize

Methods inherited from Binding

build, #compile_fragment, #get, #initialize, #read_fragment, #read_fragment_for, #set, #uncompile_fragment, #write_fragment, #write_fragment_for

Methods included from Binding::Prepare

#representer_module_for

Constructor Details

This class inherits a constructor from Representable::Binding

Class Method Details

.build_for(definition, *args) ⇒ Object



6
7
8
9
# File 'lib/representable/bindings/yaml_bindings.rb', line 6

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

Instance Method Details

#deserialize_methodObject



30
31
32
# File 'lib/representable/bindings/yaml_bindings.rb', line 30

def deserialize_method
  :from_hash
end

#serialize(value) ⇒ Object



16
17
18
# File 'lib/representable/bindings/yaml_bindings.rb', line 16

def serialize(value)
  write_scalar super(value)
end

#serialize_methodObject



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

def serialize_method
  :to_ast
end

#write(map, value) ⇒ Object



11
12
13
14
# File 'lib/representable/bindings/yaml_bindings.rb', line 11

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

#write_scalar(value) ⇒ Object



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

def write_scalar(value)
  return value if typed?

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