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 not0
. -
#initialize(cmd, status, out, err) ⇒ Result
constructor
A new instance of Result.
-
#ok? ⇒ Boolean
true
if #status is0
. -
#to_h ⇒ Hash<Symbol, V>
Get a Hash containing the instance variable values for easy logging, JSON dumping, etc.
Constructor Details
#initialize(cmd, status, out, err) ⇒ Result
Returns a new instance of Result.
45 46 47 48 49 50 |
# File 'lib/cmds/result.rb', line 45 def initialize cmd, status, out, err @cmd = cmd @status = status @out = out @err = err end |
Instance Attribute Details
#cmd ⇒ String (readonly)
The command string that was executed.
17 18 19 |
# File 'lib/cmds/result.rb', line 17 def cmd @cmd end |
#err ⇒ String (readonly)
The command process' standard error.
38 39 40 |
# File 'lib/cmds/result.rb', line 38 def err @err end |
#out ⇒ String (readonly)
The command process' standard output.
31 32 33 |
# File 'lib/cmds/result.rb', line 31 def out @out end |
#status ⇒ Fixnum (readonly)
The command process' exit status code.
24 25 26 |
# File 'lib/cmds/result.rb', line 24 def status @status end |
Instance Method Details
#assert ⇒ Result
Raises an error if the command failed (exited with a #status other
than 0
).
74 75 76 77 |
# File 'lib/cmds/result.rb', line 74 def assert Cmds.check_status @cmd, @status, @err self end |
#error? ⇒ Boolean
Returns true
if #status is not 0
.
62 63 64 |
# File 'lib/cmds/result.rb', line 62 def error? ! ok? end |
#ok? ⇒ Boolean
Returns true
if #status is 0
.
55 56 57 |
# File 'lib/cmds/result.rb', line 55 def ok? @status == 0 end |
#to_h ⇒ Hash<Symbol, V>
Get a Hash containing the instance variable values for easy logging, JSON dumping, etc.
89 90 91 92 93 |
# File 'lib/cmds/result.rb', line 89 def to_h instance_variables.map { |name| [name.to_s.sub('@', '').to_sym, instance_variable_get( name )] }.to_h end |