Class: Lomic::EventEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/lomic/EventEngine.rb

Instance Method Summary collapse

Constructor Details

#initializeEventEngine

Returns a new instance of EventEngine.


5
6
7
8
# File 'lib/lomic/EventEngine.rb', line 5

def initialize
  @stack = []
  @counter = 0 # the number of event code blocks executed
end

Instance Method Details

#counterObject


32
33
34
# File 'lib/lomic/EventEngine.rb', line 32

def counter
  @counter
end

#next_eventObject


28
29
30
# File 'lib/lomic/EventEngine.rb', line 28

def next_event
  @next_event
end

#run(event_name, rules) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lomic/EventEngine.rb', line 10

def run(event_name, rules)
  add_sort_events rules
  @next_event = event_name
  
  begin
    event_name = @next_event
    @next_event = nil
    for event in @events[event_name]
      # event code blocks can set @next_event through set_next
      instance_eval &event.block
    end
  end while @next_event.nil? == false
end

#set_next(event_name) ⇒ Object


24
25
26
# File 'lib/lomic/EventEngine.rb', line 24

def set_next(event_name)
  @next_event = event_name
end