Class: Cmds::Result
- Inherits:
-
Object
- Object
- Cmds::Result
- Defined in:
- lib/cmds/result.rb
Overview
a simple data structure returned from calling #capture on a Cmd instance.
it contains the exit status code, standard output and standard error, as well as the actual string command issued (after all substitutions).
instances also have a few convenience methods.
Instance Attribute Summary collapse
-
#cmd ⇒ String
readonly
The command string that was executed.
-
#err ⇒ String
readonly
The command process' standard error.
-
#out ⇒ String
readonly
The command process' standard output.
-
#status ⇒ Fixnum
readonly
The command process' exit status code.
Instance Method Summary collapse
-
#assert ⇒ Result
raises an error if the command failed (exited with a #status other than
0). -
#error? ⇒ Boolean
True if #status is not
0. -
#initialize(cmd, status, out, err) ⇒ Result
constructor
A new instance of Result.
-
#ok? ⇒ Boolean
True if #status is
0.
Constructor Details
#initialize(cmd, status, out, err) ⇒ Result
Returns a new instance of Result.
31 32 33 34 35 36 |
# File 'lib/cmds/result.rb', line 31 def initialize cmd, status, out, err @cmd = cmd @status = status @out = out @err = err end |
Instance Attribute Details
#cmd ⇒ String (readonly)
Returns the command string that was executed.
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 |
# File 'lib/cmds/result.rb', line 24 class Result attr_reader :cmd, :status, :out, :err # @param cmd [String] {#cmd} attribute. # @param status [Fixnum] {#status} attribute. # @param out [String] {#out} attribute. # @param err [String] {#err} attribute. def initialize cmd, status, out, err @cmd = cmd @status = status @out = out @err = err end # @return [Boolean] true if {#status} is `0`. def ok? @status == 0 end # @return [Boolean] true if {#status} is not `0`. def error? ! ok? end # raises an error if the command failed (exited with a {#status} other # than `0`). # # @return [Result] it's self (so that it can be chained). # # @raise [SystemCallError] if the command failed. # def assert Cmds.check_status @cmd, @status, @err self end # raise_error end |
#err ⇒ String (readonly)
Returns the command process' standard error.
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 |
# File 'lib/cmds/result.rb', line 24 class Result attr_reader :cmd, :status, :out, :err # @param cmd [String] {#cmd} attribute. # @param status [Fixnum] {#status} attribute. # @param out [String] {#out} attribute. # @param err [String] {#err} attribute. def initialize cmd, status, out, err @cmd = cmd @status = status @out = out @err = err end # @return [Boolean] true if {#status} is `0`. def ok? @status == 0 end # @return [Boolean] true if {#status} is not `0`. def error? ! ok? end # raises an error if the command failed (exited with a {#status} other # than `0`). # # @return [Result] it's self (so that it can be chained). # # @raise [SystemCallError] if the command failed. # def assert Cmds.check_status @cmd, @status, @err self end # raise_error end |
#out ⇒ String (readonly)
Returns the command process' standard output.
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 |
# File 'lib/cmds/result.rb', line 24 class Result attr_reader :cmd, :status, :out, :err # @param cmd [String] {#cmd} attribute. # @param status [Fixnum] {#status} attribute. # @param out [String] {#out} attribute. # @param err [String] {#err} attribute. def initialize cmd, status, out, err @cmd = cmd @status = status @out = out @err = err end # @return [Boolean] true if {#status} is `0`. def ok? @status == 0 end # @return [Boolean] true if {#status} is not `0`. def error? ! ok? end # raises an error if the command failed (exited with a {#status} other # than `0`). # # @return [Result] it's self (so that it can be chained). # # @raise [SystemCallError] if the command failed. # def assert Cmds.check_status @cmd, @status, @err self end # raise_error end |
#status ⇒ Fixnum (readonly)
Returns the command process' exit status code.
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 |
# File 'lib/cmds/result.rb', line 24 class Result attr_reader :cmd, :status, :out, :err # @param cmd [String] {#cmd} attribute. # @param status [Fixnum] {#status} attribute. # @param out [String] {#out} attribute. # @param err [String] {#err} attribute. def initialize cmd, status, out, err @cmd = cmd @status = status @out = out @err = err end # @return [Boolean] true if {#status} is `0`. def ok? @status == 0 end # @return [Boolean] true if {#status} is not `0`. def error? ! ok? end # raises an error if the command failed (exited with a {#status} other # than `0`). # # @return [Result] it's self (so that it can be chained). # # @raise [SystemCallError] if the command failed. # def assert Cmds.check_status @cmd, @status, @err self end # raise_error end |
Instance Method Details
#assert ⇒ Result
raises an error if the command failed (exited with a #status other
than 0).
55 56 57 58 |
# File 'lib/cmds/result.rb', line 55 def assert Cmds.check_status @cmd, @status, @err self end |
#error? ⇒ Boolean
Returns true if #status is not 0.
44 45 46 |
# File 'lib/cmds/result.rb', line 44 def error? ! ok? end |
#ok? ⇒ Boolean
Returns true if #status is 0.
39 40 41 |
# File 'lib/cmds/result.rb', line 39 def ok? @status == 0 end |