Class: RLM::Sandbox::Mock
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#executed_code ⇒ Object
readonly
Returns the value of attribute executed_code.
-
#runtime_bridge ⇒ Object
readonly
Returns the value of attribute runtime_bridge.
-
#skills ⇒ Object
readonly
Returns the value of attribute skills.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #exec(code) ⇒ Object
-
#initialize(handler: nil) ⇒ Mock
constructor
A new instance of Mock.
- #prepare(context:, tools:, skills:, runtime_bridge:) ⇒ Object
- #prepared? ⇒ Boolean
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
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/rlm/sandbox/mock.rb', line 6 def context @context end |
#executed_code ⇒ Object (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_bridge ⇒ Object (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 |
#skills ⇒ Object (readonly)
Returns the value of attribute skills.
6 7 8 |
# File 'lib/rlm/sandbox/mock.rb', line 6 def skills @skills end |
#tools ⇒ Object (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
#cleanup ⇒ Object
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
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
15 16 17 |
# File 'lib/rlm/sandbox/mock.rb', line 15 def prepared? @prepared end |