Class: Sevgi::Executor::Scope
- Inherits:
-
Object
- Object
- Sevgi::Executor::Scope
- Defined in:
- lib/sevgi/executor/scope.rb
Overview
Holds one isolated Sevgi script execution scope and its result.
Constant Summary collapse
- Error =
Error raised by low-level executor scope operations.
Class.new(::Sevgi::Error)
- MAIN_MODULE =
Constant name used for the temporary script module under Sevgi.
:Main
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#recent ⇒ Object?
readonly
Last expression result from the executed source.
-
#scope ⇒ Module
readonly
Isolated module where script source is evaluated.
Instance Method Summary collapse
-
#call(source, receiver = nil) { ... } ⇒ Sevgi::Executor::Scope
private
Executes one source object in this scope.
-
#error? ⇒ Boolean
Reports whether execution captured an error.
-
#initialize(scope = nil) ⇒ void
constructor
Creates a script execution scope.
-
#load(file) { ... } ⇒ Sevgi::Executor::Scope
private
Loads a file into this existing execution scope.
-
#peek ⇒ Sevgi::Executor::Source?
private
Returns the most recently pushed source.
-
#stack ⇒ Array<String>
Returns the unique source stack for this execution.
Constructor Details
#initialize(scope = nil) ⇒ void
Creates a script execution scope.
21 22 23 24 25 26 |
# File 'lib/sevgi/executor/scope.rb', line 21 def initialize(scope = nil) @scope = scope || main @recent = nil @error = nil @stack = {} end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
16 |
# File 'lib/sevgi/executor/scope.rb', line 16 attr_reader :scope, :recent, :error |
#recent ⇒ Object? (readonly)
Returns last expression result from the executed source.
16 |
# File 'lib/sevgi/executor/scope.rb', line 16 attr_reader :scope, :recent, :error |
#scope ⇒ Module (readonly)
Returns isolated module where script source is evaluated.
16 17 18 |
# File 'lib/sevgi/executor/scope.rb', line 16 def scope @scope end |
Instance Method Details
#call(source, receiver = nil) { ... } ⇒ Sevgi::Executor::Scope
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Executes one source object in this scope.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sevgi/executor/scope.rb', line 39 def call(source, receiver = nil, &boot) push(source) tap do @recent = run(source, receiver, &boot) # rubocop:disable Lint/RescueException rescue Exception => e @error = Executor::Error.new(e, self) throw(:result, self) # rubocop:enable Lint/RescueException end end |
#error? ⇒ Boolean
Reports whether execution captured an error.
30 |
# File 'lib/sevgi/executor/scope.rb', line 30 def error? = !error.nil? |
#load(file) { ... } ⇒ Sevgi::Executor::Scope
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Loads a file into this existing execution scope.
61 |
# File 'lib/sevgi/executor/scope.rb', line 61 def load(file, &block) = call(Source.load(file), &block) |
#peek ⇒ Sevgi::Executor::Source?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the most recently pushed source.
70 |
# File 'lib/sevgi/executor/scope.rb', line 70 def peek = @stack[@stack.keys.last] |
#stack ⇒ Array<String>
Returns the unique source stack for this execution.
65 |
# File 'lib/sevgi/executor/scope.rb', line 65 def stack = @stack.keys |