Class: RLM::Sandbox::Mock

Inherits:
Base
  • Object
show all
Defined in:
lib/rlm/sandbox/mock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler: nil) ⇒ Mock

Returns a new instance of Mock.



8
9
10
11
12
13
# File 'lib/rlm/sandbox/mock.rb', line 8

def initialize(handler: nil)
  super()
  @handler = handler
  @executed_code = []
  @prepared = false
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/rlm/sandbox/mock.rb', line 6

def context
  @context
end

#executed_codeObject (readonly)

Returns the value of attribute executed_code.



6
7
8
# File 'lib/rlm/sandbox/mock.rb', line 6

def executed_code
  @executed_code
end

#runtime_bridgeObject (readonly)

Returns the value of attribute runtime_bridge.



6
7
8
# File 'lib/rlm/sandbox/mock.rb', line 6

def runtime_bridge
  @runtime_bridge
end

#skillsObject (readonly)

Returns the value of attribute skills.



6
7
8
# File 'lib/rlm/sandbox/mock.rb', line 6

def skills
  @skills
end

#toolsObject (readonly)

Returns the value of attribute tools.



6
7
8
# File 'lib/rlm/sandbox/mock.rb', line 6

def tools
  @tools
end

Instance Method Details

#cleanupObject



38
39
40
41
42
43
44
45
# File 'lib/rlm/sandbox/mock.rb', line 38

def cleanup
  @prepared = false
  @executed_code.clear
  @context = nil
  @tools = nil
  @skills = nil
  @runtime_bridge = nil
end

#exec(code) ⇒ Object

Raises:



28
29
30
31
32
33
34
35
36
# File 'lib/rlm/sandbox/mock.rb', line 28

def exec(code)
  raise SandboxError, "Sandbox not prepared" unless @prepared

  @executed_code << code
  return ExecutionResult.new(status: :ok, stdout: "") if @handler.nil?

  result = @handler.call(code, context: @context, bridge: @runtime_bridge)
  result.is_a?(ExecutionResult) ? result : ExecutionResult.new(stdout: result.to_s)
end

#prepare(context:, tools:, skills:, runtime_bridge:) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rlm/sandbox/mock.rb', line 19

def prepare(context:, tools:, skills:, runtime_bridge:)
  @prepared = true
  @context = context
  @tools = tools
  @skills = skills
  @runtime_bridge = runtime_bridge
  ExecutionResult.new(status: :ok)
end

#prepared?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rlm/sandbox/mock.rb', line 15

def prepared?
  @prepared
end