Class: Eventsimple::EventDispatcher::RuleSet
- Inherits:
-
Object
- Object
- Eventsimple::EventDispatcher::RuleSet
- Defined in:
- lib/eventsimple/event_dispatcher.rb
Instance Method Summary collapse
-
#for(event) ⇒ Object
Return a ReactorSet containing all Reactors matching an Event Reactors will be in the order in which they were registered.
-
#initialize ⇒ RuleSet
constructor
A new instance of RuleSet.
-
#register(events:, sync:, async:) ⇒ Object
Register events with their sync and async Reactors.
Constructor Details
#initialize ⇒ RuleSet
Returns a new instance of RuleSet.
45 46 47 |
# File 'lib/eventsimple/event_dispatcher.rb', line 45 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 Reactors will be in the order in which they were registered
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/eventsimple/event_dispatcher.rb', line 59 def for(event) reactors = ReactorSet.new @rules.each do |event_class, rule| # Match event by class including ancestors. e.g. All events match a role for BaseEvent. if event.is_a?(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
50 51 52 53 54 55 |
# File 'lib/eventsimple/event_dispatcher.rb', line 50 def register(events:, sync:, async:) events.each do |event| @rules[event].add_sync sync @rules[event].add_async async end end |