Sha256: cc8cef6390e6f4c33eb06b892c39e557864516d6ba52f2a27232aa96f02f172d

Contents?: true

Size: 917 Bytes

Versions: 7

Compression:

Stored size: 917 Bytes

Contents

require 'representable/bindings/yaml_bindings'

module Representable
  module YAML
    include Hash

    def self.included(base)
      base.class_eval do
        include Representable
        #self.representation_wrap = true # let representable compute it.
        register_feature Representable::YAML
      end
    end


    def from_yaml(doc, options={})
      hash = Psych.load(doc)
      from_hash(hash, options, PropertyBinding)
    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, PropertyBinding)
      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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
representable-2.0.4 lib/representable/yaml.rb
representable-2.0.3 lib/representable/yaml.rb
representable-2.0.2 lib/representable/yaml.rb
representable-2.0.1 lib/representable/yaml.rb
representable-2.0.0 lib/representable/yaml.rb
representable-2.0.0.rc2 lib/representable/yaml.rb
representable-2.0.0.rc1 lib/representable/yaml.rb