Sha256: 37d17c1e4f54fcc26726e7f6852c34df1ed72dcf8a3d75e0e58a389fc9726c91

Contents?: true

Size: 1021 Bytes

Versions: 2

Compression:

Stored size: 1021 Bytes

Contents

# encoding: utf-8
require "logstash/api/service"
require "logstash/api/commands/system/basicinfo_command"
require "logstash/api/commands/system/plugins_command"
require "logstash/api/commands/stats"
require "logstash/api/commands/node"


module LogStash
  module Api
    class CommandFactory
      attr_reader :factory, :service

      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
        }
      end

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logstash-core-5.0.0.alpha4.snapshot3-java lib/logstash/api/command_factory.rb
logstash-core-5.0.0.alpha4.snapshot2-java lib/logstash/api/command_factory.rb