Class: Spud::TaskRunners::SpudTaskRunner::Shell::Command
- Inherits:
-
Object
- Object
- Spud::TaskRunners::SpudTaskRunner::Shell::Command
- Extended by:
- T::Sig
- Defined in:
- lib/spud/task_runners/spud_task_runner/shell/command.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(driver, command, silent: false, handle: STDOUT) ⇒ Command
constructor
A new instance of Command.
- #issue! ⇒ Object
Constructor Details
#initialize(driver, command, silent: false, handle: STDOUT) ⇒ Command
Returns a new instance of Command.
25 26 27 28 29 30 31 32 |
# File 'lib/spud/task_runners/spud_task_runner/shell/command.rb', line 25 def initialize(driver, command, silent: false, handle: STDOUT) @command = command @driver = driver @silent = silent @handle = handle @result = T.let(nil, T.nilable(Result)) end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
15 16 17 |
# File 'lib/spud/task_runners/spud_task_runner/shell/command.rb', line 15 def result @result end |
Class Method Details
.call(driver, command, silent: false, handle: STDOUT) ⇒ Object
18 19 20 21 22 |
# File 'lib/spud/task_runners/spud_task_runner/shell/command.rb', line 18 def self.call(driver, command, silent: false, handle: STDOUT) cmd = new(driver, command, silent: silent, handle: handle) cmd.issue! cmd.result end |
Instance Method Details
#issue! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/spud/task_runners/spud_task_runner/shell/command.rb', line 35 def issue! capturer = StringIO.new Open3.popen2e(@command) do |_stdin, stdout, thread| @driver.register_subprocess(thread.pid) loop do line = stdout.gets break unless line @handle.write line unless @silent capturer.puts line end @result = Result.new(capturer.string, T.cast(thread.value, Process::Status)) end @driver.register_subprocess(nil) end |