Class: ProductTaxonomy::CommandExecutor
- Inherits:
-
Object
- Object
- ProductTaxonomy::CommandExecutor
- Defined in:
- lib/product_taxonomy/command_executor.rb
Constant Summary collapse
- DEFAULT_RUNNER =
Open3.method(:capture3)
Instance Method Summary collapse
- #capture(*command, chdir:, failure_message:) ⇒ Object
-
#initialize(command_runner: DEFAULT_RUNNER) ⇒ CommandExecutor
constructor
A new instance of CommandExecutor.
- #run!(*command, chdir:, failure_message:) ⇒ Object
Constructor Details
#initialize(command_runner: DEFAULT_RUNNER) ⇒ CommandExecutor
Returns a new instance of CommandExecutor.
9 10 11 |
# File 'lib/product_taxonomy/command_executor.rb', line 9 def initialize(command_runner: DEFAULT_RUNNER) @command_runner = command_runner end |
Instance Method Details
#capture(*command, chdir:, failure_message:) ⇒ Object
23 24 25 26 27 |
# File 'lib/product_taxonomy/command_executor.rb', line 23 def capture(*command, chdir:, failure_message:) @command_runner.call(*command, chdir:) rescue SystemCallError => error raise "#{} #{error.}" end |
#run!(*command, chdir:, failure_message:) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/product_taxonomy/command_executor.rb', line 13 def run!(*command, chdir:, failure_message:) stdout, stderr, status = capture(*command, chdir:, failure_message:) return stdout if status.success? details = stderr.strip details = stdout.strip if details.empty? = details.empty? ? : "#{} #{details}" raise end |