Class: Sevgi::Executor::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/sevgi/executor/scope.rb

Constant Summary collapse

Error =
Class.new(::Sevgi::Error)
MAIN_MODULE =
:Main

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope = nil) ⇒ Scope

Returns a new instance of Scope.



10
11
12
13
14
15
# File 'lib/sevgi/executor/scope.rb', line 10

def initialize(scope = nil)
  @scope = scope || main
  @recent = nil
  @error = nil
  @stack = {}
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/sevgi/executor/scope.rb', line 8

def error
  @error
end

#recentObject (readonly)

Returns the value of attribute recent.



8
9
10
# File 'lib/sevgi/executor/scope.rb', line 8

def recent
  @recent
end

#scopeObject (readonly)

Returns the value of attribute scope.



8
9
10
# File 'lib/sevgi/executor/scope.rb', line 8

def scope
  @scope
end

Instance Method Details

#call(source, receiver = nil, &boot) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sevgi/executor/scope.rb', line 19

def call(source, receiver = nil, &boot)
  push(source)

  tap do
    @recent = begin
      boot(receiver, &boot)
      evaluate(source)
    end

    # rubocop:disable Lint/RescueException
  rescue Exception => e
    @error = Executor::Error.new(e, self)

    throw(:result, self)
    # rubocop:enable Lint/RescueException
  end
end

#error?Boolean

Returns:

  • (Boolean)


17
# File 'lib/sevgi/executor/scope.rb', line 17

def error? = !error.nil?

#load(file, &block) ⇒ Object



37
# File 'lib/sevgi/executor/scope.rb', line 37

def load(file, &block) = call(Source.load(file), &block)

#peekObject



41
# File 'lib/sevgi/executor/scope.rb', line 41

def peek = @stack[@stack.keys.last]

#stackObject



39
# File 'lib/sevgi/executor/scope.rb', line 39

def stack = @stack.keys