Class: Microsandbox::SshOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/microsandbox/ssh.rb

Overview

The result of an Microsandbox::SshClient#exec call. Like ExecOutput, ‘stdout`/`stderr` are the captured bytes decoded as UTF-8 (lenient); use `stdout_bytes`/ `stderr_bytes` for the raw ASCII-8BIT bytes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ SshOutput

Returns a new instance of SshOutput.



15
16
17
18
19
20
# File 'lib/microsandbox/ssh.rb', line 15

def initialize(data)
  @status = data["status"]
  @success = data["success"]
  @stdout_bytes = data["stdout"]
  @stderr_bytes = data["stderr"]
end

Instance Attribute Details

#statusInteger (readonly)

Returns the remote command’s exit status.

Returns:

  • (Integer)

    the remote command’s exit status



9
10
11
# File 'lib/microsandbox/ssh.rb', line 9

def status
  @status
end

#stderr_bytesString (readonly)

Returns raw stderr bytes (ASCII-8BIT).

Returns:

  • (String)

    raw stderr bytes (ASCII-8BIT)



13
14
15
# File 'lib/microsandbox/ssh.rb', line 13

def stderr_bytes
  @stderr_bytes
end

#stdout_bytesString (readonly)

Returns raw stdout bytes (ASCII-8BIT).

Returns:

  • (String)

    raw stdout bytes (ASCII-8BIT)



11
12
13
# File 'lib/microsandbox/ssh.rb', line 11

def stdout_bytes
  @stdout_bytes
end

Instance Method Details

#failure?Boolean

Returns whether the command exited non-zero.

Returns:

  • (Boolean)

    whether the command exited non-zero



26
# File 'lib/microsandbox/ssh.rb', line 26

def failure? = !@success

#inspectObject



40
41
42
43
# File 'lib/microsandbox/ssh.rb', line 40

def inspect
  "#<Microsandbox::SshOutput status=#{@status} success=#{@success} " \
    "stdout=#{stdout.bytesize}B stderr=#{stderr.bytesize}B>"
end

#stderrString

Returns stderr decoded as UTF-8.

Returns:

  • (String)

    stderr decoded as UTF-8



34
35
36
# File 'lib/microsandbox/ssh.rb', line 34

def stderr
  @stderr ||= @stderr_bytes.dup.force_encoding(Encoding::UTF_8)
end

#stdoutString

Returns stdout decoded as UTF-8.

Returns:

  • (String)

    stdout decoded as UTF-8



29
30
31
# File 'lib/microsandbox/ssh.rb', line 29

def stdout
  @stdout ||= @stdout_bytes.dup.force_encoding(Encoding::UTF_8)
end

#success?Boolean

Returns whether the command exited with status 0.

Returns:

  • (Boolean)

    whether the command exited with status 0



23
# File 'lib/microsandbox/ssh.rb', line 23

def success? = @success

#to_sObject



38
# File 'lib/microsandbox/ssh.rb', line 38

def to_s = stdout