Class: Plugin::RecordModifierOutput::DynamicExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/out_record_modifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(param_key, param_value, prepare_value) ⇒ DynamicExpander



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/fluent/plugin/out_record_modifier.rb', line 200

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 "      def expand(tag, time, record, tag_parts)\n        \#{__str_eval_code__}\n      end\n    EORUBY\n  else\n    @param_value = param_value\n  end\n\n  begin\n    eval prepare_value if prepare_value\n  rescue SyntaxError\n    raise ConfigError, \"Pass invalid syntax parameter : key = prepare_value, value = \#{prepare_value}\"\n  end\n\n  begin\n    # check eval genarates wrong code or not\n    expand(nil, nil, nil, nil)\n  rescue SyntaxError\n    raise ConfigError, \"Pass invalid syntax parameter : key = \#{param_key}, value = \#{param_value}\"\n  rescue\n    # Ignore other runtime errors\n  end\nend\n",  __FILE__, __LINE__ + 1

Instance Attribute Details

#param_valueObject (readonly)

Returns the value of attribute param_value.



198
199
200
# File 'lib/fluent/plugin/out_record_modifier.rb', line 198

def param_value
  @param_value
end

Instance Method Details

#expand(tag, time, record, tag_parts) ⇒ Object

Default implementation for fixed value. This is overwritten when parameter contains ‘$xxx’ placeholder



233
234
235
# File 'lib/fluent/plugin/out_record_modifier.rb', line 233

def expand(tag, time, record, tag_parts)
  @param_value
end