Class: ProcessExecuter::Result
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ProcessExecuter::Result
- Defined in:
- lib/process_executer/result.rb
Overview
A decorator for Process::Status that adds the following attributes:
command
: the command that was used to spawn the processoptions
: the options that were used to spawn the processelapsed_time
: the secs the command ranstdout
: the captured stdout outputstderr
: the captured stderr outputtimed_out?
: true if the process timed out
Instance Attribute Summary collapse
-
#command ⇒ Array
readonly
The command that was used to spawn the process.
-
#elapsed_time ⇒ Numeric?
readonly
The secs the command ran.
-
#options ⇒ Hash
readonly
The options that were used to spawn the process.
-
#timed_out? ⇒ Boolean
readonly
True if the process timed out and was sent the SIGKILL signal.
Instance Method Summary collapse
-
#initialize(status, command:, options:, timed_out:, elapsed_time:) ⇒ Result
constructor
Create a new Result object.
-
#stderr ⇒ String?
Return the captured stderr output.
-
#stdout ⇒ String?
Return the captured stdout output.
-
#success? ⇒ true?
Overrides the default success? method to return nil if the process timed out.
-
#to_s ⇒ String
Return a string representation of the result.
Constructor Details
permalink #initialize(status, command:, options:, timed_out:, elapsed_time:) ⇒ Result
Create a new Result object
46 47 48 49 50 51 52 |
# File 'lib/process_executer/result.rb', line 46 def initialize(status, command:, options:, timed_out:, elapsed_time:) super(status) @command = command @options = @timed_out = timed_out @elapsed_time = elapsed_time end |
Instance Attribute Details
permalink #command ⇒ Array (readonly)
The command that was used to spawn the process
59 60 61 |
# File 'lib/process_executer/result.rb', line 59 def command @command end |
permalink #elapsed_time ⇒ Numeric? (readonly)
The secs the command ran
74 75 76 |
# File 'lib/process_executer/result.rb', line 74 def elapsed_time @elapsed_time end |
permalink #options ⇒ Hash (readonly)
The options that were used to spawn the process
67 68 69 |
# File 'lib/process_executer/result.rb', line 67 def @options end |
permalink #timed_out? ⇒ Boolean (readonly)
True if the process timed out and was sent the SIGKILL signal
83 84 85 |
# File 'lib/process_executer/result.rb', line 83 def timed_out? @timed_out end |
Instance Method Details
permalink #stderr ⇒ String?
Return the captured stderr output
This output is only returned if the :err
option value is a
ProcessExecuter::MonitoredPipe
.
143 144 145 146 147 148 |
# File 'lib/process_executer/result.rb', line 143 def stderr pipe = .stderr_redirection_value return nil unless pipe.is_a?(ProcessExecuter::MonitoredPipe) pipe.destination.string end |
permalink #stdout ⇒ String?
Return the captured stdout output
This output is only returned if the :out
option value is a
ProcessExecuter::MonitoredPipe
.
123 124 125 126 127 128 |
# File 'lib/process_executer/result.rb', line 123 def stdout pipe = .stdout_redirection_value return nil unless pipe.is_a?(ProcessExecuter::MonitoredPipe) pipe.destination.string end |
permalink #success? ⇒ true?
Overrides the default success? method to return nil if the process timed out
This is because when a timeout occurs, Windows will still return true.
96 97 98 99 100 |
# File 'lib/process_executer/result.rb', line 96 def success? return nil if timed_out? # rubocop:disable Style/ReturnNilInPredicateMethodDefinition super end |
permalink #to_s ⇒ String
Return a string representation of the result
106 107 108 |
# File 'lib/process_executer/result.rb', line 106 def to_s "#{super}#{timed_out? ? " timed out after #{.timeout_after}s" : ''}" end |