Class: Cliqr::Executor::Router Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cliqr/executor/router.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Used for routing the command to the appropriate command handler based on the interface config

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Cliqr::Interface::Router

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new Router instance

Parameters:



16
17
18
# File 'lib/cliqr/executor/router.rb', line 16

def initialize(config)
  @config = config
end

Instance Method Details

#handle(context, **options) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handle a command invocation by routing to appropriate command handler

Parameters:

  • context (Cliqr::CLI::CommandContext)

    Context in which to execute the command

  • options (Hash)

    Hash of options to configure the [Cliqr::CLI::CommandRunner]

Returns:

  • (Integer)

    Exit code of the command execution



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cliqr/executor/router.rb', line 26

def handle(context, **options)
  handler = @config.handler
  runner = CommandRunnerFactory.get(options)
  runner.run do
    if handler.is_a?(Proc)
      context.instance_eval(&handler)
    else
      handler.execute(context)
    end
  end
end