Class: Microsandbox::SshOutput
- Inherits:
-
Object
- Object
- Microsandbox::SshOutput
- 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
-
#status ⇒ Integer
readonly
The remote command’s exit status.
-
#stderr_bytes ⇒ String
readonly
Raw stderr bytes (ASCII-8BIT).
-
#stdout_bytes ⇒ String
readonly
Raw stdout bytes (ASCII-8BIT).
Instance Method Summary collapse
-
#failure? ⇒ Boolean
Whether the command exited non-zero.
-
#initialize(data) ⇒ SshOutput
constructor
A new instance of SshOutput.
- #inspect ⇒ Object
-
#stderr ⇒ String
Stderr decoded as UTF-8 (lossy).
-
#stdout ⇒ String
Stdout decoded as UTF-8 (lossy).
-
#success? ⇒ Boolean
Whether the command exited with status 0.
- #to_s ⇒ Object
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
#status ⇒ Integer (readonly)
Returns the remote command’s exit status.
10 11 12 |
# File 'lib/microsandbox/ssh.rb', line 10 def status @status end |
#stderr_bytes ⇒ String (readonly)
Returns raw stderr bytes (ASCII-8BIT).
14 15 16 |
# File 'lib/microsandbox/ssh.rb', line 14 def stderr_bytes @stderr_bytes end |
#stdout_bytes ⇒ String (readonly)
Returns 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.
27 |
# File 'lib/microsandbox/ssh.rb', line 27 def failure? = !@success |
#inspect ⇒ Object
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 |
#stderr ⇒ String
Returns 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 |
#stdout ⇒ String
Returns 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.
24 |
# File 'lib/microsandbox/ssh.rb', line 24 def success? = @success |
#to_s ⇒ Object
39 |
# File 'lib/microsandbox/ssh.rb', line 39 def to_s = stdout |