Class: Alf::Renderer::YAML

Inherits:
Alf::Renderer show all
Defined in:
lib/alf/renderer/yaml.rb

Overview

Implements Alf::Renderer contract for outputing YAML files.

Constant Summary

Constants inherited from Alf::Renderer

DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from Alf::Renderer

#input, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Alf::Renderer

by_mime_type, #execute, #initialize, register, renderer

Methods included from Support::Registry

#listen, #listeners, #register, #registered

Constructor Details

This class inherits a constructor from Alf::Renderer

Class Method Details

.mime_typeObject


8
9
10
# File 'lib/alf/renderer/yaml.rb', line 8

def self.mime_type
  "text/yaml"
end

Instance Method Details

#each {|"---\n"| ... } ⇒ Object

Yields:

  • ("---\n")

12
13
14
15
16
17
18
19
20
21
# File 'lib/alf/renderer/yaml.rb', line 12

def each
  return to_enum unless block_given?
  require "yaml"
  yield("---\n")
  Engine::ToArray.new(input).each do |tuple|
    hash = Alf::Support.unsymbolize_keys(tuple.to_hash)
    yield "-" << hash.to_yaml[4..-1].gsub(/^/, "  ")[1..-1]
  end
  yield("\n")
end