Class: LogStash::Config::AST::PluginSection

Inherits:
Node
  • Object
show all
Defined in:
lib/logstash/config/config_ast.rb

Constant Summary collapse

@@i =
0

Instance Method Summary collapse

Instance Method Details

#compile_initializerObject

Generate ruby code to initialize all the plugins.



89
90
91
92
93
94
95
96
97
# File 'lib/logstash/config/config_ast.rb', line 89

def compile_initializer
  generate_variables
  code = []
  @variables.collect do |plugin, name|
    code << "#{name} = #{plugin.compile_initializer}"
    code << "@#{plugin.plugin_type}s << #{name}"
  end
  return code.join("\n")
end

#generate_variablesObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/logstash/config/config_ast.rb', line 104

def generate_variables
  return if !@variables.nil?
  @variables = {}
  plugins = recursive_select(Plugin)

  plugins.each do |plugin|
    # Unique number for every plugin.
    @@i += 1
    # store things as ivars, like @filter_grok_3
    var = "@#{plugin.plugin_type}_#{plugin.plugin_name}_#{@@i}"
    @variables[plugin] = var
  end
  return @variables
end

#variable(object) ⇒ Object



99
100
101
102
# File 'lib/logstash/config/config_ast.rb', line 99

def variable(object)
  generate_variables
  return @variables[object]
end