Class: Representable::YAML::Binding

Inherits:
Hash::Binding show all
Defined in:
lib/representable/yaml/binding.rb

Direct Known Subclasses

Collection

Defined Under Namespace

Classes: Collection

Instance Attribute Summary

Attributes inherited from Binding

#cached_representer, #getter, #name, #setter

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash::Binding

#read

Methods inherited from Binding

#[], build, #default_for, #initialize, #skipable_empty_value?

Methods included from Binding::Factories

#collect_for, #default_parse_fragment_functions, #default_parse_init_functions, #default_post_functions, #default_render_fragment_functions, #default_render_init_functions, #parse_functions, #pipeline_for, #render_functions

Methods included from Binding::EvaluateOption

#evaluate_option

Methods included from Binding::Deprecatable

#compile_fragment, #uncompile_fragment

Constructor Details

This class inherits a constructor from Representable::Binding

Class Method Details

.build_for(definition) ⇒ Object



6
7
8
9
# File 'lib/representable/yaml/binding.rb', line 6

def self.build_for(definition)
  return Collection.new(definition) if definition.array?
  new(definition)
end

Instance Method Details

#deserialize_methodObject



31
32
33
# File 'lib/representable/yaml/binding.rb', line 31

def deserialize_method
  :from_hash
end

#node_for(fragment) ⇒ Object

private



17
18
19
# File 'lib/representable/yaml/binding.rb', line 17

def node_for(fragment)
  write_scalar(fragment)
end

#serialize_methodObject



27
28
29
# File 'lib/representable/yaml/binding.rb', line 27

def serialize_method
  :to_ast
end

#write(map, fragment, as) ⇒ Object



11
12
13
14
# File 'lib/representable/yaml/binding.rb', line 11

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

#write_scalar(value) ⇒ Object



21
22
23
24
25
# File 'lib/representable/yaml/binding.rb', line 21

def write_scalar(value)
  return value if typed?

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