lib/representable/yaml.rb in representable-1.2.6 vs lib/representable/yaml.rb in representable-1.2.7
- old
+ new
@@ -3,18 +3,10 @@
module Representable
module YAML
include Hash
- def self.binding_for_definition(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
- PropertyBinding.new(definition)
- end
-
def self.included(base)
base.class_eval do
include Representable
extend ClassMethods
#self.representation_wrap = true # let representable compute it.
@@ -34,28 +26,38 @@
create_represented(*args, &block).from_yaml(*args)
end
end
- def from_yaml(doc, *args)
+ def from_yaml(doc, options={})
hash = Psych.load(doc)
- from_hash(hash, *args)
+ from_hash(hash, options, :yaml)
end
# Returns a Nokogiri::XML object representing this object.
def to_ast(options={})
#root_tag = options[:wrap] || representation_wrap
Psych::Nodes::Mapping.new.tap do |map|
- create_representation_with(map, options, YAML)
+ create_representation_with(map, options, :yaml)
end
end
def to_yaml(*args)
stream = Psych::Nodes::Stream.new
stream.children << doc = Psych::Nodes::Document.new
doc.children << to_ast(*args)
stream.to_yaml
+ end
+
+ private
+
+ def yaml_binding_for_definition(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
+ PropertyBinding.new(definition)
end
end
end