Class: Remotus::Result
- Inherits:
-
Object
- Object
- Remotus::Result
- Defined in:
- lib/remotus/result.rb
Overview
Class to standardize remote output from WinRM and SSH connections
Instance Attribute Summary collapse
-
#command ⇒ String
readonly
Executed command.
-
#exit_code ⇒ Integer
readonly
Exit code.
-
#output ⇒ String
readonly
All output (stdout and stderr interleaved).
-
#stderr ⇒ String
readonly
Standard error output.
-
#stdout ⇒ String
readonly
Standard output.
Instance Method Summary collapse
-
#error!(accepted_exit_codes = [0]) ⇒ Object
Raises an exception if an error was encountered.
-
#error?(accepted_exit_codes = [0]) ⇒ Boolean
Whether an error was encountered.
-
#initialize(command, stdout, stderr, output, exit_code = nil) ⇒ Result
constructor
Creates a new Result.
-
#success?(accepted_exit_codes = [0]) ⇒ Boolean
Whether the command was successful.
-
#to_s ⇒ String
Alias for all interleaved stdout and stderr output.
Constructor Details
#initialize(command, stdout, stderr, output, exit_code = nil) ⇒ Result
Creates a new Result
32 33 34 35 36 37 38 |
# File 'lib/remotus/result.rb', line 32 def initialize(command, stdout, stderr, output, exit_code = nil) @command = command @stdout = stdout @stderr = stderr @output = output @exit_code = exit_code end |
Instance Attribute Details
#command ⇒ String (readonly)
Returns executed command.
9 10 11 |
# File 'lib/remotus/result.rb', line 9 def command @command end |
#exit_code ⇒ Integer (readonly)
Returns exit code.
21 22 23 |
# File 'lib/remotus/result.rb', line 21 def exit_code @exit_code end |
#output ⇒ String (readonly)
Returns all output (stdout and stderr interleaved).
18 19 20 |
# File 'lib/remotus/result.rb', line 18 def output @output end |
#stderr ⇒ String (readonly)
Returns standard error output.
15 16 17 |
# File 'lib/remotus/result.rb', line 15 def stderr @stderr end |
#stdout ⇒ String (readonly)
Returns standard output.
12 13 14 |
# File 'lib/remotus/result.rb', line 12 def stdout @stdout end |
Instance Method Details
#error!(accepted_exit_codes = [0]) ⇒ Object
Raises an exception if an error was encountered
65 66 67 68 69 70 |
# File 'lib/remotus/result.rb', line 65 def error!(accepted_exit_codes = [0]) return unless error?(accepted_exit_codes) raise Remotus::ResultError, "Error encountered executing #{@command}! Exit code #{@exit_code} was returned " \ "while a value in #{accepted_exit_codes} was expected.\n#{output}" end |
#error?(accepted_exit_codes = [0]) ⇒ Boolean
Whether an error was encountered
56 57 58 |
# File 'lib/remotus/result.rb', line 56 def error?(accepted_exit_codes = [0]) !Array(accepted_exit_codes).include?(@exit_code) end |
#success?(accepted_exit_codes = [0]) ⇒ Boolean
Whether the command was successful
79 80 81 |
# File 'lib/remotus/result.rb', line 79 def success?(accepted_exit_codes = [0]) !error?(accepted_exit_codes) end |
#to_s ⇒ String
Alias for all interleaved stdout and stderr output
45 46 47 |
# File 'lib/remotus/result.rb', line 45 def to_s output end |