Class: Toys::Utils::Exec::Result
- Inherits:
-
Object
- Object
- Toys::Utils::Exec::Result
- Defined in:
- lib/toys/utils/exec.rb
Overview
The result returned from a subcommand execution. This includes the identifying name of the execution (if any), the result status of the execution, and any captured stream output.
Possible result statuses are:
- The process failed to start. #failed? will return true, and #exception will return an exception describing the failure (often an errno).
- The process executed and exited with a normal exit code. Either #success? or #error? will return true, and #exit_code will return the numeric exit code.
- The process executed but was terminated by an uncaught signal. #signaled? will return true, and #term_signal will return the numeric signal code.
Instance Attribute Summary collapse
-
#captured_err ⇒ String?
readonly
The captured error string.
-
#captured_out ⇒ String?
readonly
The captured output string.
-
#exception ⇒ Exception?
readonly
The exception raised if a process couldn't be started.
-
#name ⇒ Object
readonly
The subcommand's name.
-
#status ⇒ Process::Status?
readonly
The Ruby process status object, providing various information about the ending state of the process.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns true if the subprocess terminated with a nonzero status, or false if the process failed to start, terminated due to a signal, or returned a zero status.
-
#exit_code ⇒ Integer?
The numeric status code for a process that exited normally,.
-
#failed? ⇒ Boolean
Returns true if the subprocess failed to start, or false if the process was able to execute.
-
#signaled? ⇒ Boolean
Returns true if the subprocess terminated due to an unhandled signal, or false if the process failed to start or exited normally.
-
#success? ⇒ Boolean
Returns true if the subprocess terminated with a zero status, or false if the process failed to start, terminated due to a signal, or returned a nonzero status.
-
#term_signal ⇒ Integer?
The numeric signal code that caused process termination.
Instance Attribute Details
#captured_err ⇒ String? (readonly)
The captured error string.
833 834 835 |
# File 'lib/toys/utils/exec.rb', line 833 def captured_err @captured_err end |
#captured_out ⇒ String? (readonly)
The captured output string.
825 826 827 |
# File 'lib/toys/utils/exec.rb', line 825 def captured_out @captured_out end |
#exception ⇒ Exception? (readonly)
The exception raised if a process couldn't be started.
Exactly one of #exception and #status will be non-nil.
855 856 857 |
# File 'lib/toys/utils/exec.rb', line 855 def exception @exception end |
#name ⇒ Object (readonly)
The subcommand's name.
817 818 819 |
# File 'lib/toys/utils/exec.rb', line 817 def name @name end |
#status ⇒ Process::Status? (readonly)
The Ruby process status object, providing various information about the ending state of the process.
Exactly one of #exception and #status will be non-nil.
845 846 847 |
# File 'lib/toys/utils/exec.rb', line 845 def status @status end |
Instance Method Details
#error? ⇒ Boolean
Returns true if the subprocess terminated with a nonzero status, or false if the process failed to start, terminated due to a signal, or returned a zero status.
925 926 927 928 |
# File 'lib/toys/utils/exec.rb', line 925 def error? code = exit_code !code.nil? && !code.zero? end |
#exit_code ⇒ Integer?
The numeric status code for a process that exited normally,
Exactly one of #exception, #exit_code, and #term_signal will be non-nil.
868 869 870 |
# File 'lib/toys/utils/exec.rb', line 868 def exit_code status&.exitstatus end |
#failed? ⇒ Boolean
Returns true if the subprocess failed to start, or false if the process was able to execute.
892 893 894 |
# File 'lib/toys/utils/exec.rb', line 892 def failed? status.nil? end |
#signaled? ⇒ Boolean
Returns true if the subprocess terminated due to an unhandled signal, or false if the process failed to start or exited normally.
902 903 904 |
# File 'lib/toys/utils/exec.rb', line 902 def signaled? !term_signal.nil? end |
#success? ⇒ Boolean
Returns true if the subprocess terminated with a zero status, or false if the process failed to start, terminated due to a signal, or returned a nonzero status.
913 914 915 916 |
# File 'lib/toys/utils/exec.rb', line 913 def success? code = exit_code !code.nil? && code.zero? end |
#term_signal ⇒ Integer?
The numeric signal code that caused process termination.
Exactly one of #exception, #exit_code, and #term_signal will be non-nil.
882 883 884 |
# File 'lib/toys/utils/exec.rb', line 882 def term_signal status&.termsig end |