Class: Pechkin::Command::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/command.rb

Overview

Dispatch command. Commands are placed in fixed order to allow matching rules be executed in right way. For example at first we check for –add-auth and than for –check. At the moment only RunServer should be last element of this sequence.

Constant Summary collapse

COMMANDS =
[
  AddAuth,
  Check,
  List,
  SendData,
  RunServer
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli_options) ⇒ Dispatcher

Returns a new instance of Dispatcher.

Parameters:

  • cli_options (OpenStruct)

    command line options object



28
29
30
# File 'lib/pechkin/command.rb', line 28

def initialize(cli_options)
  @options = cli_options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



25
26
27
# File 'lib/pechkin/command.rb', line 25

def options
  @options
end

Instance Method Details

#dispatchObject

Dispatch command according to provided options



33
34
35
# File 'lib/pechkin/command.rb', line 33

def dispatch
  COMMANDS.map { |c| c.new(options) }.find(&:matches?)
end