class Fluent::Format::Format

Public Class Methods

new(config_dev, opts = {}) click to toggle source

Initialize

@param [IO|String] config filename or IO Object

# File lib/fluent/format/format.rb, line 7
def initialize(config_dev, opts = {})
  @config_dev = config_dev
  @use_v1_config = opts[:use_v1_config]
end

Public Instance Methods

read(config_dev, use_v1_config) click to toggle source

Read config (this does formatting)

@param [IO|String] config_dev config filename or IO Object @raise Fluent::ConfigParseError if conf has syntax errors @raise Fluent::ConfigError if plugin raises config error @return [String] the formatted config

# File lib/fluent/format/format.rb, line 28
def read(config_dev, use_v1_config)
  if config_dev.respond_to?(:read) # IO object
    str = config_dev.read
    fname = '-'
    basename = '-'
  else
    str = File.read(config_dev)
    fname = File.basename(config_dev)
    basename = File.dirname(config_dev)
  end
  Fluent::Config.parse(str, fname, basename, use_v1_config)
end
run() click to toggle source

Format config

@raise Fluent::ConfigParseError if conf has syntax errors @raise Fluent::ConfigError if plugin raises config error @return [String] the formatted config

# File lib/fluent/format/format.rb, line 17
def run
  formatted = read(@config_dev, @use_v1_config)
  indent(formatted)
end

Private Instance Methods

indent(conf) click to toggle source

hmm, ugly workaround

# File lib/fluent/format/format.rb, line 44
def indent(conf)
  lines = conf.to_s.split("\n")[1..-2] # remove <ROOT> and </ROOT>
  lines = lines.map {|line| line[2..-1] } # remove heading 2 white spaces
  lines.join("\n")
end