Class: Fluent::Plugin::ConfigExpanderFilter

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



47
48
49
# File 'lib/fluent/plugin/filter_config_expander.rb', line 47

def method_missing(name, *args, &block)
  @plugin.__send__(name, *args, &block)
end

Instance Method Details

#builtin_mappingObject



20
21
22
# File 'lib/fluent/plugin/filter_config_expander.rb', line 20

def builtin_mapping
  {'__hostname__' => @hostname, '__HOSTNAME__' => @hostname, '${hostname}' => @hostname, '${HOSTNAME}' => @hostname}
end

#configure(conf) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fluent/plugin/filter_config_expander.rb', line 31

def configure(conf)
  super

  ex = expand_config(@config_config.corresponding_config_element)
  type = ex['@type']
  @plugin = Fluent::Plugin.new_input(type)
  @plugin.context_router = self.event_emitter_router(conf['@label'])
  @plugin.configure(ex)
  mark_used(@config_config.corresponding_config_element)

  self.extend SingleForwardable
  override_methods = self.methods + @plugin.methods - SingleForwardable.instance_methods - Object.instance_methods
  override_methods.uniq!
  def_delegators(:@plugin, *override_methods)
end

#expand_config(conf) ⇒ Object



24
25
26
27
28
29
# File 'lib/fluent/plugin/filter_config_expander.rb', line 24

def expand_config(conf)
  ex = Fluent::Config::Expander.expand(conf, builtin_mapping())
  ex.name = 'filter' # name/arg will be ignored by Plugin#configure, but anyway
  ex.arg = conf.arg
  ex
end

#mark_used(conf) ⇒ Object



15
16
17
18
# File 'lib/fluent/plugin/filter_config_expander.rb', line 15

def mark_used(conf)
  conf.keys.each {|key| conf[key] } # to suppress unread configuration warning
  conf.elements.each{|e| mark_used(e)}
end