Class: SystemCall::Result
- Inherits:
-
Object
- Object
- SystemCall::Result
- Includes:
- Comparable
- Defined in:
- lib/system_call/result.rb
Overview
A class that represents a result of a system call.
Instance Attribute Summary collapse
-
#error_result ⇒ String
readonly
The STDERR of the result.
-
#exit_status ⇒ Process::Status
readonly
The exit status of the result.
-
#success_result ⇒ String
readonly
The STDOUT of the result.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compares the result with the result of #to_s from another object.
-
#error? ⇒ Boolean
Indicates whether the command has not been executed successfully.
-
#exit_code ⇒ Integer
Gets the exit code of the process.
-
#initialize(exit_status, success_result, error_result) ⇒ Result
constructor
Initializes a new Result.
-
#result ⇒ String
(also: #to_s)
Returns the command result.
-
#success? ⇒ Boolean
Indicates whether the command has been executed successfully.
Constructor Details
#initialize(exit_status, success_result, error_result) ⇒ Result
Initializes a new SystemCall::Result.
24 25 26 27 28 |
# File 'lib/system_call/result.rb', line 24 def initialize(exit_status, success_result, error_result) @exit_status = exit_status @success_result = success_result @error_result = error_result end |
Instance Attribute Details
#error_result ⇒ String (readonly)
Returns The STDERR of the result.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/system_call/result.rb', line 13 class Result include Comparable attr_reader :exit_status, :success_result, :error_result ## # Initializes a new {Result}. # # @param exit_status [Process::Status] The exit status of the result. # @param success_result [String] The STDOUT of the result. # @param error_result [String] The STDERR of the result. def initialize(exit_status, success_result, error_result) @exit_status = exit_status @success_result = success_result @error_result = error_result end ## # Gets the exit code of the process. # # @return [Integer] def exit_code exit_status.exitstatus end ## # Indicates whether the command has been executed successfully. # # @return [Boolean] def success? exit_status.success? end ## # Indicates whether the command has not been executed successfully. # # @return [Boolean] def error? !success? end ## # Returns the command result. # # @return [String] Returns result from {#success_result} when command exited # successfully. Otherwise returns result from {#error_result}. def result success? ? success_result : error_result end alias to_s result ## # Compares the result with the result of {#to_s} from another object. # # @param other [#to_s, nil] # @return [Integer, nil] def <=>(other) return nil if other.nil? result <=> other.to_s end end |
#exit_status ⇒ Process::Status (readonly)
Returns The exit status of the result.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/system_call/result.rb', line 13 class Result include Comparable attr_reader :exit_status, :success_result, :error_result ## # Initializes a new {Result}. # # @param exit_status [Process::Status] The exit status of the result. # @param success_result [String] The STDOUT of the result. # @param error_result [String] The STDERR of the result. def initialize(exit_status, success_result, error_result) @exit_status = exit_status @success_result = success_result @error_result = error_result end ## # Gets the exit code of the process. # # @return [Integer] def exit_code exit_status.exitstatus end ## # Indicates whether the command has been executed successfully. # # @return [Boolean] def success? exit_status.success? end ## # Indicates whether the command has not been executed successfully. # # @return [Boolean] def error? !success? end ## # Returns the command result. # # @return [String] Returns result from {#success_result} when command exited # successfully. Otherwise returns result from {#error_result}. def result success? ? success_result : error_result end alias to_s result ## # Compares the result with the result of {#to_s} from another object. # # @param other [#to_s, nil] # @return [Integer, nil] def <=>(other) return nil if other.nil? result <=> other.to_s end end |
#success_result ⇒ String (readonly)
Returns The STDOUT of the result.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/system_call/result.rb', line 13 class Result include Comparable attr_reader :exit_status, :success_result, :error_result ## # Initializes a new {Result}. # # @param exit_status [Process::Status] The exit status of the result. # @param success_result [String] The STDOUT of the result. # @param error_result [String] The STDERR of the result. def initialize(exit_status, success_result, error_result) @exit_status = exit_status @success_result = success_result @error_result = error_result end ## # Gets the exit code of the process. # # @return [Integer] def exit_code exit_status.exitstatus end ## # Indicates whether the command has been executed successfully. # # @return [Boolean] def success? exit_status.success? end ## # Indicates whether the command has not been executed successfully. # # @return [Boolean] def error? !success? end ## # Returns the command result. # # @return [String] Returns result from {#success_result} when command exited # successfully. Otherwise returns result from {#error_result}. def result success? ? success_result : error_result end alias to_s result ## # Compares the result with the result of {#to_s} from another object. # # @param other [#to_s, nil] # @return [Integer, nil] def <=>(other) return nil if other.nil? result <=> other.to_s end end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compares the result with the result of #to_s from another object.
70 71 72 73 74 |
# File 'lib/system_call/result.rb', line 70 def <=>(other) return nil if other.nil? result <=> other.to_s end |
#error? ⇒ Boolean
Indicates whether the command has not been executed successfully.
50 51 52 |
# File 'lib/system_call/result.rb', line 50 def error? !success? end |
#exit_code ⇒ Integer
Gets the exit code of the process.
34 35 36 |
# File 'lib/system_call/result.rb', line 34 def exit_code exit_status.exitstatus end |
#result ⇒ String Also known as: to_s
Returns the command result.
59 60 61 |
# File 'lib/system_call/result.rb', line 59 def result success? ? success_result : error_result end |
#success? ⇒ Boolean
Indicates whether the command has been executed successfully.
42 43 44 |
# File 'lib/system_call/result.rb', line 42 def success? exit_status.success? end |