Class: Remotus::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/remotus/result.rb

Overview

Class to standardize remote output from WinRM and SSH connections

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, stdout, stderr, output, exit_code = nil) ⇒ Result

Creates a new Result

Parameters:

  • command (String)

    command executed

  • stdout (String)

    standard output

  • stderr (String)

    standard error output

  • output (String)

    all output (stdout and stderr interleaved)

  • exit_code (Integer) (defaults to: nil)

    exit code



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

#commandString (readonly)

Returns executed command.

Returns:

  • (String)

    executed command



9
10
11
# File 'lib/remotus/result.rb', line 9

def command
  @command
end

#exit_codeInteger (readonly)

Returns exit code.

Returns:

  • (Integer)

    exit code



21
22
23
# File 'lib/remotus/result.rb', line 21

def exit_code
  @exit_code
end

#outputString (readonly)

Returns all output (stdout and stderr interleaved).

Returns:

  • (String)

    all output (stdout and stderr interleaved)



18
19
20
# File 'lib/remotus/result.rb', line 18

def output
  @output
end

#stderrString (readonly)

Returns standard error output.

Returns:

  • (String)

    standard error output



15
16
17
# File 'lib/remotus/result.rb', line 15

def stderr
  @stderr
end

#stdoutString (readonly)

Returns standard output.

Returns:

  • (String)

    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

Parameters:

  • accepted_exit_codes (Array) (defaults to: [0])

    integer array of acceptable exit codes

Raises:



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

Parameters:

  • accepted_exit_codes (Array) (defaults to: [0])

    integer array of acceptable exit codes

Returns:

  • (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

Parameters:

  • accepted_exit_codes (Array) (defaults to: [0])

    integer array of acceptable exit codes

Returns:

  • (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_sString

Alias for all interleaved stdout and stderr output

Returns:

  • (String)

    interleaved output



45
46
47
# File 'lib/remotus/result.rb', line 45

def to_s
  output
end