Class: LogStash::Plugins::Registry::PluginRawContext

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/plugins/registry.rb

Constant Summary collapse

HOOK_FILE =
"logstash_registry.rb"
NAME_DELIMITER =
"-"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ PluginRawContext

Returns a new instance of PluginRawContext.



36
37
38
39
# File 'lib/logstash/plugins/registry.rb', line 36

def initialize(spec)
  @spec = spec
  @destructured_name = spec.name.split(NAME_DELIMITER)
end

Instance Attribute Details

#specObject (readonly)

Returns the value of attribute spec.



34
35
36
# File 'lib/logstash/plugins/registry.rb', line 34

def spec
  @spec
end

Instance Method Details

#execute_hooks!Object



67
68
69
# File 'lib/logstash/plugins/registry.rb', line 67

def execute_hooks!
  require hooks_file
end

#has_hooks?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/logstash/plugins/registry.rb', line 63

def has_hooks?
  !hooks_file.nil?
end

#hooks_fileObject

In the context of the plugin, the hook file available need to exist in any top level required paths.

Example for the logstash-output-elasticsearch we have this line in the gemspec.

s.require_paths = [“lib”], so the we will expect to have a ‘logstash_registry.rb` file in the `lib` directory.



56
57
58
59
60
61
# File 'lib/logstash/plugins/registry.rb', line 56

def hooks_file
  @hook_file ||= spec.full_require_paths.collect do |path|
    f = ::File.join(path, HOOK_FILE)
    ::File.exist?(f) ? f : nil
  end.compact.first
end

#nameObject



41
42
43
# File 'lib/logstash/plugins/registry.rb', line 41

def name
  @destructured_name[2..-1].join(NAME_DELIMITER)
end

#typeObject



45
46
47
# File 'lib/logstash/plugins/registry.rb', line 45

def type
  @destructured_name[1]
end