Sha256: 63fc11124b166998b989cc4a1f71d10a9b389bb1bcc26a9df1e21e7661905413
Contents?: true
Size: 1.19 KB
Versions: 7
Compression:
Stored size: 1.19 KB
Contents
require 'representable/binding' module Representable module YAML class PropertyBinding < Representable::Hash::PropertyBinding def self.build_for(definition, *args) return CollectionBinding.new(definition, *args) if definition.array? new(definition, *args) end def write(map, value) map.children << Psych::Nodes::Scalar.new(from) map.children << serialize(value) # FIXME: should be serialize. end def serialize(value) write_scalar super(value) end def write_scalar(value) return value if typed? Psych::Nodes::Scalar.new(value.to_s) end def serialize_method :to_ast end def deserialize_method :from_hash end end class CollectionBinding < PropertyBinding def serialize(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(fragment) # FIXME: redundant from Hash::Bindings CollectionDeserializer.new(self).deserialize(fragment) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems