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