Sha256: 211a09de7fca9184f34a39903680b48eae668af6bb9a117279d31fb4abc0ea30
Contents?: true
Size: 1.76 KB
Versions: 1
Compression:
Stored size: 1.76 KB
Contents
require 'representable/binding' module Representable module YAML module ObjectBinding include Binding::Object def serialize_method :to_ast end def deserialize_method :from_hash end def write_scalar(value) value end end class PropertyBinding < Representable::Hash::PropertyBinding def self.build_for(definition) return CollectionBinding.new(definition) if definition.array? #return HashBinding.new(definition) if definition.hash? and not definition.options[:use_attributes] # FIXME: hate this. #return AttributeHashBinding.new(definition) if definition.hash? and definition.options[:use_attributes] #return AttributeBinding.new(definition) if definition.attribute new(definition) end def initialize(*args) # FIXME. make generic. super extend ObjectBinding if typed? end def write(map, value) map.children << Psych::Nodes::Scalar.new(from) map.children << serialize_for(value) # FIXME: should be serialize. end def serialize_for(value) write_scalar serialize(value) end def write_scalar(value) Psych::Nodes::Scalar.new(value.to_s) end end class CollectionBinding < PropertyBinding def serialize_for(value) Psych::Nodes::Sequence.new.tap do |seq| seq.style = Psych::Nodes::Sequence::FLOW if options[:style] == :flow value.each { |obj| seq.children << super(obj) } end end def deserialize_from(fragment) # FIXME: redundant from Hash::Bindings fragment.collect { |item_fragment| deserialize(item_fragment) } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
representable-1.2.8 | lib/representable/bindings/yaml_bindings.rb |