Class: Sevgi::Executor
- Inherits:
-
Object
- Object
- Sevgi::Executor
- Includes:
- Singleton
- Defined in:
- lib/sevgi/executor.rb,
lib/sevgi/executor/error.rb,
lib/sevgi/executor/scope.rb,
lib/sevgi/executor/source.rb
Overview
Executes Sevgi script source inside an isolated module scope.
The executor is used by script mode and by the Load DSL word to preserve a
useful load stack while keeping DSL methods out of the caller's global object
whenever possible.
Defined Under Namespace
Class Method Summary collapse
-
.execute(string, file: nil, line: nil, require: nil, receiver: nil) { ... } ⇒ Sevgi::Executor::Scope?
Executes Ruby source inside a managed Sevgi script scope.
-
.execute_file(file, require: nil, receiver: nil) { ... } ⇒ Sevgi::Executor::Scope?
Executes a file inside a managed Sevgi script scope.
-
.load(file) ⇒ Sevgi::Executor::Scope
private
Loads a script file inside the current executor scope.
-
.shutdown ⇒ Sevgi::Executor::Scope?
private
Removes the current executor scope.
Instance Method Summary collapse
-
#create(scope = nil) ⇒ Sevgi::Executor::Scope
private
Creates and pushes a new executor scope.
-
#current ⇒ Sevgi::Executor::Scope?
private
Returns the active executor scope.
-
#initialize ⇒ Executor
constructor
A new instance of Executor.
-
#shutdown ⇒ Sevgi::Executor::Scope?
private
Removes the active executor scope.
Constructor Details
#initialize ⇒ Executor
Returns a new instance of Executor.
74 |
# File 'lib/sevgi/executor.rb', line 74 def initialize = @scopes = [] |
Class Method Details
.execute(string, file: nil, line: nil, require: nil, receiver: nil) { ... } ⇒ Sevgi::Executor::Scope?
Executes Ruby source inside a managed Sevgi script scope.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sevgi/executor.rb', line 39 def self.execute(string, file: nil, line: nil, require: nil, receiver: nil, &block) return if string.empty? interrupt = Signal.trap("INT") { Kernel.abort("") } ::Kernel.require(require) if require scope = instance.create catch(:result) { scope.call(Source.new(string:, file:, line:), receiver, &block) } ensure Signal.trap("INT", interrupt) if interrupt instance.shutdown if scope end |
.execute_file(file, require: nil, receiver: nil) { ... } ⇒ Sevgi::Executor::Scope?
Executes a file inside a managed Sevgi script scope.
63 64 65 |
# File 'lib/sevgi/executor.rb', line 63 def self.execute_file(file, require: nil, receiver: nil, &block) execute(::File.read(file), file: file, line: 1, require:, receiver:, &block) end |
.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 script file inside the current executor scope.
23 24 25 26 27 |
# File 'lib/sevgi/executor.rb', line 23 def self.load(file, ...) PanicError.("box stack empty; create a box first") unless instance.current instance.current.load(file, ...) end |
.shutdown ⇒ 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.
Removes the current executor scope.
70 71 72 |
# File 'lib/sevgi/executor.rb', line 70 def self.shutdown instance.shutdown end |
Instance Method Details
#create(scope = 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.
Creates and pushes a new executor scope.
80 |
# File 'lib/sevgi/executor.rb', line 80 def create(scope = nil) = Scope.new(scope).tap { @scopes << it } |
#current ⇒ 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.
Returns the active executor scope.
85 |
# File 'lib/sevgi/executor.rb', line 85 def current = @scopes.last |
#shutdown ⇒ 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.
Removes the active executor scope.
90 |
# File 'lib/sevgi/executor.rb', line 90 def shutdown = @scopes.pop |