Module: Scallop::Executor
- Defined in:
- lib/scallop/executor.rb
Overview
Executes command and returns result.
Class Method Summary collapse
- .build_result(capture3, timing) ⇒ Object
- .measure ⇒ Object
- .run(command) ⇒ Object
- .run!(command) ⇒ Object
Class Method Details
.build_result(capture3, timing) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/scallop/executor.rb', line 25 def self.build_result(capture3, timing) stdout, stderr, status = capture3 Result .new( stdout: stdout.strip, stderr: stderr.strip, status: status, timing: timing, ) .freeze end |
.measure ⇒ Object
19 20 21 22 23 |
# File 'lib/scallop/executor.rb', line 19 def self.measure result = nil timing = Benchmark.measure { result = yield } [result, timing] end |
.run(command) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/scallop/executor.rb', line 6 def self.run(command) capture3, timing = measure do Open3.capture3(command) end build_result(capture3, timing) end |
.run!(command) ⇒ Object
13 14 15 16 17 |
# File 'lib/scallop/executor.rb', line 13 def self.run!(command) run(command).tap do |result| raise Errors::CommandFailed.new(result.stderr, result) unless result.success? end end |