Class: ROM::Notifications::EventBus
- Inherits:
-
Object
- Object
- ROM::Notifications::EventBus
- Includes:
- Publisher
- Defined in:
- core/lib/rom/support/notifications.rb
Overview
Event bus
An event bus stores listeners (callbacks) and events
Instance Attribute Summary collapse
- #events ⇒ Object readonly
- #id ⇒ Object readonly
- #listeners ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(id, events: EMPTY_HASH, listeners: LISTENERS_HASH.dup) ⇒ EventBus
constructor
Initialize a new event bus.
-
#subscribe(event_id, query = EMPTY_HASH) {|block| ... } ⇒ Object
included
from Publisher
Subscribe to events.
-
#trigger(event_id, payload = EMPTY_HASH) ⇒ Object
included
from Publisher
Trigger an event.
Constructor Details
#initialize(id, events: EMPTY_HASH, listeners: LISTENERS_HASH.dup) ⇒ EventBus
Initialize a new event bus
227 228 229 230 231 |
# File 'core/lib/rom/support/notifications.rb', line 227 def initialize(id, events: EMPTY_HASH, listeners: LISTENERS_HASH.dup) @id = id @listeners = listeners @events = events end |
Instance Attribute Details
#events ⇒ Object (readonly)
214 215 216 |
# File 'core/lib/rom/support/notifications.rb', line 214 def events @events end |
#id ⇒ Object (readonly)
210 211 212 |
# File 'core/lib/rom/support/notifications.rb', line 210 def id @id end |
#listeners ⇒ Object (readonly)
218 219 220 |
# File 'core/lib/rom/support/notifications.rb', line 218 def listeners @listeners end |
Instance Method Details
#subscribe(event_id, query = EMPTY_HASH) {|block| ... } ⇒ Object Originally defined in module Publisher
Subscribe to events. If the query parameter is provided, filters events by payload.
#trigger(event_id, payload = EMPTY_HASH) ⇒ Object Originally defined in module Publisher
Trigger an event