Module: Komando::Command

Defined in:
lib/komando/command.rb,
lib/komando/command/dsl.rb

Defined Under Namespace

Modules: Dsl

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run!(instance_variable_declarations) ⇒ true

Instantiates and runs this command.

Parameters:

  • instance_variable_declarations (Hash)

    The list of instance variables to declare on this instance.

Returns:

  • (true)

    When the mandatory parts of the command are run to completion.



10
11
12
# File 'lib/komando/command.rb', line 10

def self.run!(instance_variable_declarations)
  new.run!(instance_variable_declarations)
end

Instance Method Details

#initialize(instance_variable_declarations = {}) ⇒ Object

The instance variables will be available in the blocks, courtesy of Ruby and it’s dynamic nature.

Parameters:

  • instance_variable_declarations (Hash) (defaults to: {})

    The list of instance variables to declare on this instance.



17
18
19
20
21
# File 'lib/komando/command.rb', line 17

def initialize(instance_variable_declarations={})
  instance_variable_declarations.each do |name, value|
    instance_variable_set("@#{name}", value)
  end
end

#logger#warn, ...

Returns a Logger-like object that will log receive #warn, #info and #debug calls. The logger can do whatever it wants with those calls.

Examples:


# config/initializers/komando.rb
require "komando/command"

module Komando::Command
  def logger
    Rails.logger
  end
end

Returns:

  • (#warn, #info, #debug)

    A Logger-like object that responds to logging commands.



49
50
51
# File 'lib/komando/command.rb', line 49

def logger
  @logger ||= Logger.new(STDERR)
end

#run!true

Executes the mandatory and best effort steps, in order of definition, raising or logging and swallowing exceptions as appropriate.

Returns:

  • (true)

    Always returns true, since exceptions indicate failure.

Raises:

  • (Exception)

    In case of a failure in the mandatory part of the command.



28
29
30
31
32
# File 'lib/komando/command.rb', line 28

def run!
  run_mandatory!
  run_best_effort
  true
end