Class: LogStash::Config::AST::Plugin

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

Instance Method Summary collapse

Instance Method Details

#compileObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/logstash/config/config_ast.rb', line 152

def compile
  case plugin_type
    when "input"
      return "start_input(#{variable_name})"
    when "filter"
      # This is some pretty stupid code, honestly.
      # I'd prefer much if it were put into the Pipeline itself
      # and this should simply compile to 
      #   #{variable_name}.filter(event)
      return [
        "newevents = []",
        "extra_events.each do |event|",
        "  #{variable_name}.filter(event) do |newevent|",
        "    newevents << newevent",
        "  end",
        "end",
        "extra_events += newevents",

        "#{variable_name}.filter(event) do |newevent|",
        "  extra_events << newevent",
        "end",
        "if event.cancelled?",
        "  extra_events.each(&block)",
        "  return",
        "end",
      ].map { |l| "#{l}\n" }.join("")
    when "output"
      return "#{variable_name}.handle(event)\n"
    when "codec"
      settings = attributes.recursive_select(Attribute).collect(&:compile).reject(&:empty?)
      attributes_code = "LogStash::Util.hash_merge_many(#{settings.map { |c| "{ #{c} }" }.join(", ")})"
      return "plugin(#{plugin_type.inspect}, #{plugin_name.inspect}, #{attributes_code})"
  end
end

#compile_initializerObject



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/logstash/config/config_ast.rb', line 139

def compile_initializer
  # If any parent is a Plugin, this must be a codec.

  if attributes.elements.nil?
    return "plugin(#{plugin_type.inspect}, #{plugin_name.inspect})" << (plugin_type == "codec" ? "" : "\n")
  else
    settings = attributes.recursive_select(Attribute).collect(&:compile).reject(&:empty?)

    attributes_code = "LogStash::Util.hash_merge_many(#{settings.map { |c| "{ #{c} }" }.join(", ")})"
    return "plugin(#{plugin_type.inspect}, #{plugin_name.inspect}, #{attributes_code})" << (plugin_type == "codec" ? "" : "\n")
  end
end

#plugin_nameObject



131
132
133
# File 'lib/logstash/config/config_ast.rb', line 131

def plugin_name
  return name.text_value
end

#plugin_typeObject



123
124
125
126
127
128
129
# File 'lib/logstash/config/config_ast.rb', line 123

def plugin_type
  if recursive_select_parent(Plugin).any?
    return "codec"
  else
    return recursive_select_parent(PluginSection).first.plugin_type.text_value
  end
end

#variable_nameObject



135
136
137
# File 'lib/logstash/config/config_ast.rb', line 135

def variable_name
  return recursive_select_parent(PluginSection).first.variable(self)
end