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.
Scope objects belong to one executor run and are pushed onto the current fiber's executor stack. They are not shared between concurrent executions.
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.
-
#capture(source, error) ⇒ Sevgi::Executor::Scope
private
Captures a preprocessing failure for 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
When no module is supplied, the internal module reports its name as Sevgi::Main for readable Ruby error
messages without publishing a process-global Sevgi::Main constant.
Creates a script execution scope.
23 24 25 26 27 28 |
# File 'lib/sevgi/executor/scope.rb', line 23 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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sevgi/executor/scope.rb', line 41 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 |
#capture(source, error) ⇒ 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.
Captures a preprocessing failure for this scope.
61 62 63 64 65 |
# File 'lib/sevgi/executor/scope.rb', line 61 def capture(source, error) push(source) @error = Executor::Error.new(error, self) self end |
#error? ⇒ Boolean
Reports whether execution captured an error.
32 |
# File 'lib/sevgi/executor/scope.rb', line 32 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.
File-read failures are captured as Error on this scope.
Loads a file into this existing execution scope.
74 75 76 77 78 79 |
# File 'lib/sevgi/executor/scope.rb', line 74 def load(file, &block) call(Source.load(file), &block) rescue ::SystemCallError => e capture(Source.new(string: "", file:, line: 1), e) throw(:result, self) end |
#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.
89 |
# File 'lib/sevgi/executor/scope.rb', line 89 def peek = @stack[@stack.keys.last] |
#stack ⇒ Array<String>
The stack is owned by this scope and is not shared with concurrent executions.
Returns the unique source stack for this execution.
84 |
# File 'lib/sevgi/executor/scope.rb', line 84 def stack = @stack.keys |