Class: LogStash::Api::CommandFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/api/command_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ CommandFactory

Returns a new instance of CommandFactory.



15
16
17
18
19
20
21
22
23
24
# File 'lib/logstash/api/command_factory.rb', line 15

def initialize(service)
  @service = service
  @factory = {
    :system_basic_info => ::LogStash::Api::Commands::System::BasicInfo,
    :plugins_command => ::LogStash::Api::Commands::System::Plugins,
    :stats => ::LogStash::Api::Commands::Stats,
    :node => ::LogStash::Api::Commands::Node,
    :default_metadata => ::LogStash::Api::Commands::DefaultMetadata
  }
end

Instance Attribute Details

#factoryObject (readonly)

Returns the value of attribute factory.



13
14
15
# File 'lib/logstash/api/command_factory.rb', line 13

def factory
  @factory
end

#serviceObject (readonly)

Returns the value of attribute service.



13
14
15
# File 'lib/logstash/api/command_factory.rb', line 13

def service
  @service
end

Instance Method Details

#build(*klass_path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/logstash/api/command_factory.rb', line 26

def build(*klass_path)
  # Get a nested path with args like (:parent, :child)
  klass = klass_path.reduce(factory) {|acc,v| acc[v]}

  if klass
    klass.new(service)
  else
    raise ArgumentError, "Class path '#{klass_path}' does not map to command!"
  end
end