Class: LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Plugin

Inherits:
Node
  • Object
show all
Defined in:
lib/logstash/compiler/lscl.rb

Constant Summary

Constants included from Helpers

Helpers::AND_METHOD, Helpers::BOOLEAN_DSL_METHOD_SIGNATURE, Helpers::NAND_METHOD, Helpers::OR_METHOD, Helpers::XOR_METHOD

Instance Method Summary collapse

Methods inherited from Node

#section_type

Methods included from Helpers

#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

#exprObject



75
76
77
# File 'lib/logstash/compiler/lscl.rb', line 75

def expr
  jdsl.iPlugin(source_meta, plugin_type_enum, self.plugin_name, self.expr_attributes)
end

#expr_attributesObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/logstash/compiler/lscl.rb', line 96

def expr_attributes
  # Turn attributes into a hash map
  self.attributes.recursive_select(Attribute).map(&:expr).map {|k,v|
    if v.java_kind_of?(Java::OrgLogstashConfigIrExpression::ValueExpression)
      [k, v.get]
    else
      [k,v]
    end
  }.reduce({}) do |hash, kv|
    k, v = kv
    existing = hash[k]
    if existing.nil?
      hash[k] = v
    elsif existing.kind_of?(::Hash)
      # For legacy reasons, a config can contain multiple `AST::Attribute`s with the same name
      # and a hash-type value (e.g., "match" in the grok filter), which are merged into a single
      # hash value; e.g., `{"match" => {"baz" => "bar"}, "match" => {"foo" => "bulb"}}` is
      # interpreted as `{"match" => {"baz" => "bar", "foo" => "blub"}}`.
      # (NOTE: this bypasses `AST::Hash`'s ability to detect duplicate keys)
      hash[k] = ::LogStash::Util.hash_merge_many(existing, v)
    elsif existing.kind_of?(::Array)
      hash[k] = existing.push(*v)
    else
      hash[k] = [existing, v] unless v == existing
    end
    hash
  end
end

#plugin_nameObject



92
93
94
# File 'lib/logstash/compiler/lscl.rb', line 92

def plugin_name
  return name.text_value
end

#plugin_type_enumObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/logstash/compiler/lscl.rb', line 79

def plugin_type_enum
  case section_type
  when "input"
    Java::OrgLogstashConfigIr::PluginDefinition::Type::INPUT
  when "codec"
    Java::OrgLogstashConfigIr::PluginDefinition::Type::CODEC
  when "filter"
    Java::OrgLogstashConfigIr::PluginDefinition::Type::FILTER
  when "output"
    Java::OrgLogstashConfigIr::PluginDefinition::Type::OUTPUT
  end
end