Class: Eventsimple::EventDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/eventsimple/event_dispatcher.rb

Defined Under Namespace

Classes: ReactorSet, RuleSet

Class Method Summary collapse

Class Method Details

.dispatch(event) ⇒ Object

Dispatches events to matching Reactors once. Called by all events after they are created.



29
30
31
32
33
34
35
36
37
38
# File 'lib/eventsimple/event_dispatcher.rb', line 29

def self.dispatch(event)
  reactors = rules.for(event)
  reactors.sync.each do |reactor|
    reactor.perform_now(event)
    event.reload
  end
  reactors.async.each do |reactor|
    reactor.perform_later(event)
  end
end

.rulesObject



40
41
42
# File 'lib/eventsimple/event_dispatcher.rb', line 40

def self.rules
  @rules ||= RuleSet.new
end