Class: LogStash::Config::AST::Plugin
- Inherits:
-
Node
- Object
- Treetop::Runtime::SyntaxNode
- Node
- LogStash::Config::AST::Plugin
show all
- Defined in:
- lib/logstash/config/config_ast.rb
Constant Summary
LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::AND_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::BOOLEAN_DSL_METHOD_SIGNATURE, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::NAND_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::OR_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::XOR_METHOD
Instance Method Summary
collapse
Methods inherited from Node
#text_value_for_comments
#base_id, #base_protocol, #base_source_with_metadata, #base_source_with_metadata=, #compose, #compose_for, #jdsl, jdsl, #line_and_column, #source_meta
Instance Method Details
#compile ⇒ Object
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/logstash/config/config_ast.rb', line 204
def compile
case plugin_type
when "input"
return "start_input(@generated_objects[:#{variable_name}])"
when "filter"
return <<-CODE
events = @generated_objects[:#{variable_name}].multi_filter(events)
CODE
when "output"
return "targeted_outputs << @generated_objects[:#{variable_name}]\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}, #{source_meta.line}, #{source_meta.column}, #{attributes_code})"
end
end
|
#compile_initializer ⇒ Object
191
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/logstash/config/config_ast.rb', line 191
def compile_initializer
if attributes.elements.nil?
return "plugin(#{plugin_type.inspect}, #{plugin_name.inspect}, #{source_meta.line}, #{source_meta.column})" << (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}, #{source_meta.line}, #{source_meta.column}, #{attributes_code})" << (plugin_type == "codec" ? "" : "\n")
end
end
|
#compile_starting_here ⇒ Object
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/logstash/config/config_ast.rb', line 221
def compile_starting_here
return unless plugin_type == "filter"
expressions = [
LogStash::Config::AST::Branch,
LogStash::Config::AST::Plugin
]
code = []
self_branch = recursive_select_parent(LogStash::Config::AST::BranchEntry).first
branch_siblings = []
if self_branch
branch_siblings = recursive_select_parent(LogStash::Config::AST::Branch).first \
.recursive_select(LogStash::Config::AST::BranchEntry) \
.reject { |b| b == self_branch }
end
ast = recursive_select_parent(LogStash::Config::AST::Config).first
found = false
recurse(ast) do |element, depth|
next false if element.is_a?(LogStash::Config::AST::PluginSection) && element.plugin_type.text_value != "filter"
if element == self
found = true
next false
end
if found && expressions.include?(element.class)
code << element.compile
next false
end
next false if branch_siblings.include?(element)
next true
end
return code.collect { |l| "#{l}\n" }.join("")
end
|
#plugin_name ⇒ Object
183
184
185
|
# File 'lib/logstash/config/config_ast.rb', line 183
def plugin_name
return name.text_value
end
|
#plugin_type ⇒ Object
175
176
177
178
179
180
181
|
# File 'lib/logstash/config/config_ast.rb', line 175
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_name ⇒ Object
187
188
189
|
# File 'lib/logstash/config/config_ast.rb', line 187
def variable_name
return recursive_select_parent(PluginSection).first.variable(self)
end
|