Class: FluentCommandBuilder::ExecutionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent_command_builder/execution_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(executor) ⇒ ExecutionContext

Returns a new instance of ExecutionContext.



9
10
11
12
13
14
# File 'lib/fluent_command_builder/execution_context.rb', line 9

def initialize(executor)
  @executor = executor
  @should_print_on_execute = true
  @should_fail_on_error = true
  @printer = FluentCommandBuilder::Printer.new
end

Instance Attribute Details

#executorObject

Returns the value of attribute executor.



7
8
9
# File 'lib/fluent_command_builder/execution_context.rb', line 7

def executor
  @executor
end

#printerObject

Returns the value of attribute printer.



7
8
9
# File 'lib/fluent_command_builder/execution_context.rb', line 7

def printer
  @printer
end

#should_fail_on_errorObject

Returns the value of attribute should_fail_on_error.



7
8
9
# File 'lib/fluent_command_builder/execution_context.rb', line 7

def should_fail_on_error
  @should_fail_on_error
end

#should_print_on_executeObject

Returns the value of attribute should_print_on_execute.



7
8
9
# File 'lib/fluent_command_builder/execution_context.rb', line 7

def should_print_on_execute
  @should_print_on_execute
end

Instance Method Details

#execute(command, visible_command = command) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/fluent_command_builder/execution_context.rb', line 16

def execute(command, visible_command=command)
  validate_should_print_on_execute
  validate_should_fail_on_error
  print_command visible_command
  @executor.execute(command) do |status|
    raise "Command failed with status (#{status.exitstatus}): [#{visible_command}]" if @should_fail_on_error && !status.success?
  end
end