Class: Backspin::CommandResult
- Inherits:
-
Object
- Object
- Backspin::CommandResult
- Defined in:
- lib/backspin/command_result.rb
Overview
Represents the result of executing a command Stores stdout, stderr, and exit status
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compare two results for equality.
-
#failure? ⇒ Boolean
True if the command failed (non-zero exit status).
-
#initialize(stdout:, stderr:, status:) ⇒ CommandResult
constructor
A new instance of CommandResult.
- #inspect ⇒ Object
-
#success? ⇒ Boolean
True if the command succeeded (exit status 0).
-
#to_h ⇒ Hash
Hash representation of the result.
Constructor Details
#initialize(stdout:, stderr:, status:) ⇒ CommandResult
Returns a new instance of CommandResult.
9 10 11 12 13 |
# File 'lib/backspin/command_result.rb', line 9 def initialize(stdout:, stderr:, status:) @stdout = stdout @stderr = stderr @status = normalize_status(status) end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/backspin/command_result.rb', line 7 def status @status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
7 8 9 |
# File 'lib/backspin/command_result.rb', line 7 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
7 8 9 |
# File 'lib/backspin/command_result.rb', line 7 def stdout @stdout end |
Instance Method Details
#==(other) ⇒ Object
Compare two results for equality
35 36 37 38 39 |
# File 'lib/backspin/command_result.rb', line 35 def ==(other) return false unless other.is_a?(CommandResult) stdout == other.stdout && stderr == other.stderr && status == other.status end |
#failure? ⇒ Boolean
Returns true if the command failed (non-zero exit status).
21 22 23 |
# File 'lib/backspin/command_result.rb', line 21 def failure? !success? end |
#inspect ⇒ Object
41 42 43 |
# File 'lib/backspin/command_result.rb', line 41 def inspect "#<Backspin::CommandResult status=#{status} stdout=#{stdout} stderr=#{stderr}>" end |
#success? ⇒ Boolean
Returns true if the command succeeded (exit status 0).
16 17 18 |
# File 'lib/backspin/command_result.rb', line 16 def success? status.zero? end |
#to_h ⇒ Hash
Returns Hash representation of the result.
26 27 28 29 30 31 32 |
# File 'lib/backspin/command_result.rb', line 26 def to_h { "stdout" => stdout, "stderr" => stderr, "status" => status } end |