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 (lossy — invalid byte sequences are replaced with U+FFFD); 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.



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

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



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

def status
  @status
end

#stderr_bytesString (readonly)

Returns raw stderr bytes (ASCII-8BIT).

Returns:

  • (String)

    raw stderr bytes (ASCII-8BIT)



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

def stderr_bytes
  @stderr_bytes
end

#stdout_bytesString (readonly)

Returns raw stdout bytes (ASCII-8BIT).

Returns:

  • (String)

    raw stdout bytes (ASCII-8BIT)



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

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



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

def failure? = !@success

#inspectObject



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

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

#stderrString

Returns stderr decoded as UTF-8 (lossy).

Returns:

  • (String)

    stderr decoded as UTF-8 (lossy)



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

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

#stdoutString

Returns stdout decoded as UTF-8 (lossy).

Returns:

  • (String)

    stdout decoded as UTF-8 (lossy)



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

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

#success?Boolean

Returns whether the command exited with status 0.

Returns:

  • (Boolean)

    whether the command exited with status 0



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

def success? = @success

#to_sObject



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

def to_s = stdout