Class: Cmds::Result
- Inherits:
-
Object
- Object
- Cmds::Result
- Defined in:
- lib/cmds/result.rb
Overview
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.
29 30 31 32 33 34 |
# File 'lib/cmds/result.rb', line 29 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.
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 |
# File 'lib/cmds/result.rb', line 22 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 if error? msg = NRSER.squish <<-BLOCK command `#{ @cmd }` exited with status #{ @status } and stderr #{ err.inspect } BLOCK raise SystemCallError.new msg, @status end self end # raise_error end |
#err ⇒ String (readonly)
Returns the command process' standard error.
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 |
# File 'lib/cmds/result.rb', line 22 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 if error? msg = NRSER.squish <<-BLOCK command `#{ @cmd }` exited with status #{ @status } and stderr #{ err.inspect } BLOCK raise SystemCallError.new msg, @status end self end # raise_error end |
#out ⇒ String (readonly)
Returns the command process' standard output.
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 |
# File 'lib/cmds/result.rb', line 22 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 if error? msg = NRSER.squish <<-BLOCK command `#{ @cmd }` exited with status #{ @status } and stderr #{ err.inspect } BLOCK raise SystemCallError.new msg, @status end self end # raise_error end |
#status ⇒ Fixnum (readonly)
Returns the command process' exit status code.
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 |
# File 'lib/cmds/result.rb', line 22 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 if error? msg = NRSER.squish <<-BLOCK command `#{ @cmd }` exited with status #{ @status } and stderr #{ err.inspect } BLOCK raise SystemCallError.new msg, @status end self end # raise_error end |
Instance Method Details
#assert ⇒ Result
raises an error if the command failed (exited with a #status other
than 0).
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cmds/result.rb', line 53 def assert if error? msg = NRSER.squish <<-BLOCK command `#{ @cmd }` exited with status #{ @status } and stderr #{ err.inspect } BLOCK raise SystemCallError.new msg, @status end self end |
#error? ⇒ Boolean
Returns true if #status is not 0.
42 43 44 |
# File 'lib/cmds/result.rb', line 42 def error? ! ok? end |
#ok? ⇒ Boolean
Returns true if #status is 0.
37 38 39 |
# File 'lib/cmds/result.rb', line 37 def ok? @status == 0 end |