module Representable::YAML

Public Class Methods

included(base) click to toggle source
# File lib/representable/yaml.rb, line 8
def self.included(base)
  base.class_eval do
    include Representable
    #self.representation_wrap = true # let representable compute it.
    register_feature Representable::YAML
  end
end

Public Instance Methods

from_yaml(doc, options={}) click to toggle source
# File lib/representable/yaml.rb, line 17
def from_yaml(doc, options={})
  hash = Psych.load(doc)
  from_hash(hash, options, Binding)
end
to_ast(options={}) click to toggle source

Returns a Nokogiri::XML object representing this object.

# File lib/representable/yaml.rb, line 23
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
to_yaml(*args) click to toggle source
# File lib/representable/yaml.rb, line 31
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