class Fluent::RemoveEmptyOutput::RubyPlaceholderExpander

Attributes

log[R]
placeholders[R]

Public Class Methods

new(log) click to toggle source
# File lib/fluent/plugin/out_remove_empty.rb, line 145
def initialize(log)
  @log = log
end

Public Instance Methods

expand(str) click to toggle source

Replace placeholders in a string

@param [String] str the string to be replaced

# File lib/fluent/plugin/out_remove_empty.rb, line 164
def expand(str)
  str = str.gsub(/\$\{([^}]+)\}/, '#{\1}') # ${..} => #{..}
  eval "\"#{str}\"", @placeholders.instance_eval { binding }
end
prepare_placeholders(time, record, opts) click to toggle source

Get placeholders as a struct

@param [Time] time the time @param [Hash] record the record @param [Hash] opts others

# File lib/fluent/plugin/out_remove_empty.rb, line 154
def prepare_placeholders(time, record, opts)
  struct = UndefOpenStruct.new(record)
  struct.time = Time.at(time)
  opts.each {|key, value| struct.__send__("#{key}=", value) }
  @placeholders = struct
end