Module: Fuelcell::Action::Callable

Included in:
Command, OptDefinition
Defined in:
lib/fuelcell/action/callable.rb

Instance Method Summary collapse

Instance Method Details

#call(opts, args, shell) ⇒ Integer

Executes this command.

Parameters:

  • opts (Hash)

    processed opts from the cli parser

  • args (Array)

    processed args from the cli parser

  • shell (Fuelcell::Shell)

    IO abstraction

Returns:

  • (Integer)

    the exit code



31
32
33
34
35
36
37
38
# File 'lib/fuelcell/action/callable.rb', line 31

def call(opts, args, shell)
  fail 'command is not be called, callable not assigned' unless callable?
  begin
    cast_exit_code callable.call(opts, args, shell)
  rescue StandardError => e
    shell.exception e
  end
end

#callable(value = nil) ⇒ Object Also known as: run

Both getter and setting for callable object. This what the cli will execute when this command is found.

Parameters:

  • value (Object) (defaults to: nil)

    any object that implements :call

Returns:

  • (Object)


9
10
11
12
13
14
15
16
17
# File 'lib/fuelcell/action/callable.rb', line 9

def callable(value = nil)
  return @callable if value.nil?

  unless value.respond_to?(:call)
    fail ArgumentError, 'callable must implement :call'
  end

  @callable = value
end

#callable?Boolean Also known as: runnable?

Returns:

  • (Boolean)


20
21
22
# File 'lib/fuelcell/action/callable.rb', line 20

def callable?
  callable.respond_to?(:call)
end