# File lib/fluent/plugin/filter_record_modifier.rb, line 147 def initialize(param_key, param_value) if param_value.include?('${') __str_eval_code__ = parse_parameter(param_value) # Use class_eval with string instead of define_method for performance. # It can't share instructions but this is 2x+ faster than define_method in filter case. # Refer: http://tenderlovemaking.com/2013/03/03/dynamic_method_definitions.html (class << self; self; end).class_eval " def expand(tag, time, record, tag_parts) #{__str_eval_code__} end ", __FILE__, __LINE__ + 1 else @param_value = param_value end begin # check eval genarates wrong code or not expand(nil, nil, nil, nil) rescue SyntaxError raise ConfigError, "Pass invalid syntax parameter : key = #{param_key}, value = #{param_value}" rescue # Ignore other runtime errors end end
Default implementation for fixed value. This is overwritten when parameter contains '${xxx}' placeholder
# File lib/fluent/plugin/filter_record_modifier.rb, line 174 def expand(tag, time, record, tag_parts) @param_value end
# File lib/fluent/plugin/filter_record_modifier.rb, line 180 def parse_parameter(value) num_placeholders = value.scan('${').size if num_placeholders == 1 if value.start_with?('${') && value.end_with?('}') return value[2..-2] else "\"#{value.gsub('${', '#{')}\"" end else "\"#{value.gsub('${', '#{')}\"" end end end end if defined?(Filter) end