Sha256: b9e7b7f7519d6ea72ed30666167a55342e247e54947e8a3e2a2b9b4e80966117

Contents?: true

Size: 920 Bytes

Versions: 10

Compression:

Stored size: 920 Bytes

Contents

require 'representable/hash'
require 'representable/yaml/binding'

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, Binding)
    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, Binding)
      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

10 entries across 10 versions & 1 rubygems

Version Path
representable-2.3.0 lib/representable/yaml.rb
representable-2.2.3 lib/representable/yaml.rb
representable-2.2.2 lib/representable/yaml.rb
representable-2.2.1 lib/representable/yaml.rb
representable-2.2.0 lib/representable/yaml.rb
representable-2.1.8 lib/representable/yaml.rb
representable-2.1.7 lib/representable/yaml.rb
representable-2.1.6 lib/representable/yaml.rb
representable-2.1.5 lib/representable/yaml.rb
representable-2.1.4 lib/representable/yaml.rb