Class: Microsandbox::ExecEvent
- Inherits:
-
Object
- Object
- Microsandbox::ExecEvent
- Defined in:
- lib/microsandbox/exec_handle.rb
Overview
A single event from a streaming execution (Sandbox#exec_stream).
Instance Attribute Summary collapse
-
#code ⇒ Integer?
readonly
Exit code (:exited) or errno (:failed/:stdin_error).
-
#data ⇒ String?
readonly
Raw bytes (ASCII-8BIT) for :stdout/:stderr, or the message for :failed/:stdin_error.
-
#pid ⇒ Integer?
readonly
Pid (for :started).
-
#type ⇒ Symbol
readonly
:started, :stdout, :stderr, :exited, :failed, or :stdin_error.
Instance Method Summary collapse
- #exited? ⇒ Boolean
- #failed? ⇒ Boolean
-
#initialize(event) ⇒ ExecEvent
constructor
A new instance of ExecEvent.
- #inspect ⇒ Object
- #started? ⇒ Boolean
- #stderr? ⇒ Boolean
- #stdin_error? ⇒ Boolean
- #stdout? ⇒ Boolean
-
#text ⇒ String?
#data decoded as UTF-8 (lenient).
Constructor Details
#initialize(event) ⇒ ExecEvent
Returns a new instance of ExecEvent.
16 17 18 19 20 21 |
# File 'lib/microsandbox/exec_handle.rb', line 16 def initialize(event) @type = event["type"].to_sym @pid = event["pid"] @code = event["code"] @data = event["data"] end |
Instance Attribute Details
#code ⇒ Integer? (readonly)
Returns exit code (:exited) or errno (:failed/:stdin_error).
11 12 13 |
# File 'lib/microsandbox/exec_handle.rb', line 11 def code @code end |
#data ⇒ String? (readonly)
Returns raw bytes (ASCII-8BIT) for :stdout/:stderr, or the message for :failed/:stdin_error.
14 15 16 |
# File 'lib/microsandbox/exec_handle.rb', line 14 def data @data end |
#pid ⇒ Integer? (readonly)
Returns pid (for :started).
9 10 11 |
# File 'lib/microsandbox/exec_handle.rb', line 9 def pid @pid end |
#type ⇒ Symbol (readonly)
Returns :started, :stdout, :stderr, :exited, :failed, or :stdin_error.
7 8 9 |
# File 'lib/microsandbox/exec_handle.rb', line 7 def type @type end |
Instance Method Details
#exited? ⇒ Boolean
31 |
# File 'lib/microsandbox/exec_handle.rb', line 31 def exited? = @type == :exited |
#failed? ⇒ Boolean
32 |
# File 'lib/microsandbox/exec_handle.rb', line 32 def failed? = @type == :failed |
#inspect ⇒ Object
35 36 37 38 |
# File 'lib/microsandbox/exec_handle.rb', line 35 def inspect "#<Microsandbox::ExecEvent type=#{@type}#{@pid ? " pid=#{@pid}" : ""}" \ "#{@code ? " code=#{@code}" : ""}#{@data ? " data=#{@data.bytesize}B" : ""}>" end |
#started? ⇒ Boolean
28 |
# File 'lib/microsandbox/exec_handle.rb', line 28 def started? = @type == :started |
#stderr? ⇒ Boolean
30 |
# File 'lib/microsandbox/exec_handle.rb', line 30 def stderr? = @type == :stderr |
#stdin_error? ⇒ Boolean
33 |
# File 'lib/microsandbox/exec_handle.rb', line 33 def stdin_error? = @type == :stdin_error |
#stdout? ⇒ Boolean
29 |
# File 'lib/microsandbox/exec_handle.rb', line 29 def stdout? = @type == :stdout |
#text ⇒ String?
Returns #data decoded as UTF-8 (lenient).
24 25 26 |
# File 'lib/microsandbox/exec_handle.rb', line 24 def text @data && @data.dup.force_encoding(Encoding::UTF_8) end |