Module: ROM::Notifications::Publisher
- Included in:
- ROM::Notifications, EventBus
- Defined in:
- core/lib/rom/support/notifications.rb
Overview
Extension used for classes that can trigger events
Instance Method Summary collapse
-
#subscribe(event_id, query = EMPTY_HASH) {|block| ... } ⇒ Object
Subscribe to events.
-
#trigger(event_id, payload = EMPTY_HASH) ⇒ Object
Trigger an event.
Instance Method Details
#subscribe(event_id, query = EMPTY_HASH) {|block| ... } ⇒ Object
Subscribe to events. If the query parameter is provided, filters events by payload.
56 57 58 59 |
# File 'core/lib/rom/support/notifications.rb', line 56 def subscribe(event_id, query = EMPTY_HASH, &block) listeners[event_id] << [block, query] self end |
#trigger(event_id, payload = EMPTY_HASH) ⇒ Object
Trigger an event
67 68 69 70 71 72 73 |
# File 'core/lib/rom/support/notifications.rb', line 67 def trigger(event_id, payload = EMPTY_HASH) event = events[event_id] listeners[event.id].each do |(listener, query)| event.payload(payload).trigger(listener, query) end end |