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.



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

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

Instance Attribute Details

#specObject (readonly)

Returns the value of attribute spec.



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

def spec
  @spec
end

Instance Method Details

#execute_hooks!Object



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

def execute_hooks!
  require hooks_file
end

#has_hooks?Boolean

Returns:

  • (Boolean)


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

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.



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

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



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

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

#typeObject



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

def type
  @destructured_name[1]
end