class Fluent::Config::YamlParser::SectionBodyBuilder

Constants

Row

Public Class Methods

new(indent, root: false) click to toggle source
# File lib/fluent/config/yaml_parser/section_builder.rb, line 68
def initialize(indent, root: false)
  @indent = ' ' * indent
  @bodies = []
  @root = root
end

Public Instance Methods

add_line(k, v) click to toggle source
# File lib/fluent/config/yaml_parser/section_builder.rb, line 74
def add_line(k, v)
  @bodies << Row.new(k, v, @indent)
end
add_section(section) click to toggle source
# File lib/fluent/config/yaml_parser/section_builder.rb, line 78
def add_section(section)
  @bodies << section
end
to_element() click to toggle source
# File lib/fluent/config/yaml_parser/section_builder.rb, line 82
def to_element
  if @root
    return @bodies.map(&:to_element)
  end

  not_section, section = @bodies.partition { |e| e.is_a?(Row) }
  r = {}
  not_section.each do |e|
    v = e.value
    r[e.key] = v.respond_to?(:to_element) ? v.to_element : v
  end

  if @root
    section.map(&:to_element)
  else
    Fluent::Config::Element.new('', '', r, section.map(&:to_element))
  end
end
to_s() click to toggle source
# File lib/fluent/config/yaml_parser/section_builder.rb, line 101
def to_s
  @bodies.map(&:to_s).join("\n")
end