module Agave::Dump::Format::Yaml

Public Class Methods

deep_hashify_items(value) click to toggle source
# File lib/agave/dump/format/yaml.rb, line 25
def self.deep_hashify_items(value)
  case value
  when Array
    value.map { |v| deep_hashify_items(v) }
  when Hash
    value.each_with_object({}) do |(k, v), acc|
      acc[k] = deep_hashify_items(v)
    end
  when ::Agave::Local::Item
    value.to_hash
  else
    if value.respond_to?(:to_hash)
      value.to_hash
    else
      value
    end
  end
end
dump(value) click to toggle source
# File lib/agave/dump/format/yaml.rb, line 44
def self.dump(value)
  plain = deep_hashify_items(value)
  YAML.dump(plain.deep_stringify_keys).chomp.gsub(/^\-+\n/, '')
end
frontmatter_dump(value) click to toggle source
# File lib/agave/dump/format/yaml.rb, line 49
def self.frontmatter_dump(value)
  "---\n#{dump(value)}\n---"
end