Class: Enruby::Command::Base

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

rubocop:disable Metrics/AbcSize



11
12
13
14
15
16
17
18
# File 'lib/enruby/command/base.rb', line 11

def initialize(opts = {})
  @binary = opts[:binary] || configuration.binary
  @logger = opts[:logger] || configuration.logger
  @options = opts[:options] || configuration.options
  @stdin = opts[:stdin] || configuration.stdin
  @stdout = opts[:stdout] || configuration.stdout
  @stderr = opts[:stderr] || configuration.stderr
end

Instance Method Details

#execute(parameters = {}, invocation_options = {}) ⇒ Object

Executes the command instance.

Parameters:

  • parameters (Hash<String, Object>) (defaults to: {})

    The parameters used to invoke the command. See subclass documentation for details of supported options.

  • invocation_options (Hash<String, Object>) (defaults to: {})

    Additional options controlling the invocation of the command.

Options Hash (invocation_options):

  • :environment (Hash<String, String>)

    A map of environment variables to expose at command invocation time.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/enruby/command/base.rb', line 31

def execute(parameters = {}, invocation_options = {})
  parameters = resolve_parameters(parameters)
  invocation_options = resolve_invocation_options(invocation_options)

  do_before(parameters)
  result = build_and_execute_command(parameters, invocation_options)
  do_after(parameters)

  prepare_result(result, parameters, invocation_options)
rescue Lino::Errors::ExecutionError
  message = "Failed while running '#{command_name}'."
  logger.error(message)
  raise Errors::ExecutionError, message
end