Class: Dotanuki::ExecResult
- Inherits:
-
Object
- Object
- Dotanuki::ExecResult
- Defined in:
- lib/dotanuki.rb
Overview
Result of one or more command executions
Instance Attribute Summary collapse
-
#failed_index ⇒ Fixnum
readonly
Index of the command that failed, or nil if all commands succeeded.
-
#status ⇒ Fixnum
readonly
Exit status of the command that failed, nil if the command was not found and 0 if all commands succeeded.
-
#stderr ⇒ Array
readonly
Array of stderr from each command executed.
-
#stdout ⇒ Array
readonly
Array of stdout from each command executed.
Instance Method Summary collapse
-
#<<(result) ⇒ Object
Add another [ExecResult] to this.
-
#add(stdout, stderr, status) ⇒ Object
Add the result of a command execution.
-
#fail_message ⇒ Object
Returns stderr for the command that failed.
-
#failed? ⇒ Boolean
Returns true if a command has failed.
-
#initialize ⇒ ExecResult
constructor
A new instance of ExecResult.
-
#ok? ⇒ Boolean
Returns true if a command has not failed.
Constructor Details
#initialize ⇒ ExecResult
Returns a new instance of ExecResult.
44 45 46 47 48 49 |
# File 'lib/dotanuki.rb', line 44 def initialize @stdout = [] @stderr = [] @status = 0 @failed_index = nil end |
Instance Attribute Details
#failed_index ⇒ Fixnum (readonly)
Index of the command that failed, or nil if all commands succeeded
42 43 44 |
# File 'lib/dotanuki.rb', line 42 def failed_index @failed_index end |
#status ⇒ Fixnum (readonly)
Exit status of the command that failed, nil if the command was not found and 0 if all commands succeeded
38 39 40 |
# File 'lib/dotanuki.rb', line 38 def status @status end |
#stderr ⇒ Array (readonly)
Array of stderr from each command executed
32 33 34 |
# File 'lib/dotanuki.rb', line 32 def stderr @stderr end |
#stdout ⇒ Array (readonly)
Array of stdout from each command executed
28 29 30 |
# File 'lib/dotanuki.rb', line 28 def stdout @stdout end |
Instance Method Details
#<<(result) ⇒ Object
Add another [ExecResult] to this
77 78 79 80 81 |
# File 'lib/dotanuki.rb', line 77 def <<(result) raise ArgumentError unless result.is_a?(ExecResult) # TODO merge correctly add(result.stdout, result.stderr, result.status) end |
#add(stdout, stderr, status) ⇒ Object
Add the result of a command execution
67 68 69 70 71 72 73 74 |
# File 'lib/dotanuki.rb', line 67 def add(stdout, stderr, status) @stdout << stdout @stderr << stderr if status.nil? || status != 0 @status = status @failed_index = @stdout.size - 1 end end |
#fail_message ⇒ Object
Returns stderr for the command that failed
62 63 64 |
# File 'lib/dotanuki.rb', line 62 def stderr[@failed_index] end |
#failed? ⇒ Boolean
Returns true if a command has failed
52 53 54 |
# File 'lib/dotanuki.rb', line 52 def failed? status != 0 end |
#ok? ⇒ Boolean
Returns true if a command has not failed
57 58 59 |
# File 'lib/dotanuki.rb', line 57 def ok? status == 0 end |