class Fluent::RecordTransformerFilter::RubyPlaceholderExpander
Attributes
log[R]
placeholders[R]
Public Class Methods
new(params)
click to toggle source
# File lib/fluent/plugin/filter_record_transformer.rb, line 216 def initialize(params) @log = params[:log] @auto_typecast = params[:auto_typecast] end
Public Instance Methods
expand(str, force_stringify=false)
click to toggle source
# File lib/fluent/plugin/filter_record_transformer.rb, line 233 def expand(str, force_stringify=false) if @auto_typecast and !force_stringify single_placeholder_matched = str.match(/\A\${([^}]+)}\z/) if single_placeholder_matched code = single_placeholder_matched[1] return eval code, @placeholders.instance_eval { binding } end end interpolated = str.gsub(/\$\{([^}]+)\}/, '#{\1}') # ${..} => #{..} eval "\"#{interpolated}\"", @placeholders.instance_eval { binding } rescue => e log.warn "failed to expand `#{str}`", :error_class => e.class, :error => e.message log.warn_backtrace nil 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/filter_record_transformer.rb, line 226 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