Class: Microsandbox::ExecEvent

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

Overview

A single event from a streaming execution (Sandbox#exec_stream).

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeInteger? (readonly)

Returns exit code (:exited) or errno (:failed/:stdin_error).

Returns:

  • (Integer, nil)

    exit code (:exited) or errno (:failed/:stdin_error)



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

def code
  @code
end

#dataString? (readonly)

Returns raw bytes (ASCII-8BIT) for :stdout/:stderr, or the message for :failed/:stdin_error.

Returns:

  • (String, nil)

    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

#pidInteger? (readonly)

Returns pid (for :started).

Returns:

  • (Integer, nil)

    pid (for :started)



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

def pid
  @pid
end

#typeSymbol (readonly)

Returns :started, :stdout, :stderr, :exited, :failed, or :stdin_error.

Returns:

  • (Symbol)

    :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

Returns:

  • (Boolean)


31
# File 'lib/microsandbox/exec_handle.rb', line 31

def exited?       = @type == :exited

#failed?Boolean

Returns:

  • (Boolean)


32
# File 'lib/microsandbox/exec_handle.rb', line 32

def failed?       = @type == :failed

#inspectObject



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

Returns:

  • (Boolean)


28
# File 'lib/microsandbox/exec_handle.rb', line 28

def started?      = @type == :started

#stderr?Boolean

Returns:

  • (Boolean)


30
# File 'lib/microsandbox/exec_handle.rb', line 30

def stderr?       = @type == :stderr

#stdin_error?Boolean

Returns:

  • (Boolean)


33
# File 'lib/microsandbox/exec_handle.rb', line 33

def stdin_error?  = @type == :stdin_error

#stdout?Boolean

Returns:

  • (Boolean)


29
# File 'lib/microsandbox/exec_handle.rb', line 29

def stdout?       = @type == :stdout

#textString?

Returns #data decoded as UTF-8 (lenient).

Returns:

  • (String, nil)

    #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