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.



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

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

Instance Attribute Details

#specObject (readonly)

Returns the value of attribute spec.



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

def spec
  @spec
end

Instance Method Details

#execute_hooks!Object



71
72
73
# File 'lib/logstash/plugins/registry.rb', line 71

def execute_hooks!
  require hooks_file
end

#has_hooks?Boolean

Returns:

  • (Boolean)


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

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.



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

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



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

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

#typeObject



49
50
51
# File 'lib/logstash/plugins/registry.rb', line 49

def type
  @destructured_name[1]
end