Class: Evey::Dispatcher::RuleSet

Inherits:
Object
  • Object
show all
Defined in:
lib/evey/dispatcher.rb

Instance Method Summary collapse

Constructor Details

#initializeRuleSet

Returns a new instance of RuleSet.



50
51
52
# File 'lib/evey/dispatcher.rb', line 50

def initialize
  @rules ||= Hash.new { |h, k| h[k] = ReactorSet.new }
end

Instance Method Details

#for(event) ⇒ Object

Return a ReactorSet containing all Reactors matching an Event



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/evey/dispatcher.rb', line 63

def for(event)
  reactors = ReactorSet.new

  @rules.each do |event_class, rule|
    if event.class == event_class
      reactors.add_sync rule.sync
      reactors.add_async rule.async
    end
  end

  reactors
end

#register(events:, sync:, async:) ⇒ Object

Register events with their sync and async Reactors



55
56
57
58
59
60
# File 'lib/evey/dispatcher.rb', line 55

def register(events:, sync:, async:)
  events.each do |event|
    @rules[event].add_sync sync
    @rules[event].add_async async
  end
end