Class: Plugin::RecordModifierFilter::DynamicExpander
- Inherits:
-
Object
- Object
- Plugin::RecordModifierFilter::DynamicExpander
- Defined in:
- lib/fluent/plugin/filter_record_modifier.rb
Instance Method Summary collapse
-
#expand(tag, time, record, tag_parts) ⇒ Object
Default implementation for fixed value.
-
#initialize(param_key, param_value, prepare_value) ⇒ DynamicExpander
constructor
A new instance of DynamicExpander.
Constructor Details
#initialize(param_key, param_value, prepare_value) ⇒ DynamicExpander
Returns a new instance of DynamicExpander.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/fluent/plugin/filter_record_modifier.rb', line 165 def initialize(param_key, param_value, prepare_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 <<-EORUBY, __FILE__, __LINE__ + 1 def expand(tag, time, record, tag_parts) #{__str_eval_code__} end EORUBY else @param_value = param_value end begin eval prepare_value if prepare_value rescue SyntaxError raise ConfigError, "Pass invalid syntax parameter : key = prepare_value, value = #{prepare_value}" end begin # check eval genarates wrong code or not (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 |
Instance Method Details
#expand(tag, time, record, tag_parts) ⇒ Object
Default implementation for fixed value. This is overwritten when parameter contains ‘$xxx’ placeholder
198 199 200 |
# File 'lib/fluent/plugin/filter_record_modifier.rb', line 198 def (tag, time, record, tag_parts) @param_value end |