Module: ROM::Notifications
Overview
Notification subsystem
This is an abstract event bus that implements a simple pub/sub protocol. The Notifications module is used in the setup process to decouple different modules from each other.
Defined Under Namespace
Modules: Listener, Publisher Classes: Event, EventBus
Constant Summary collapse
- LISTENERS_HASH =
Hash.new { |h, k| h[k] = [] }
Class Method Summary collapse
-
.event_bus(id) ⇒ Notifications::EventBus
Build an event bus.
- .events ⇒ Object private
- .listeners ⇒ Object private
-
.subscribe(event_id, query = EMPTY_HASH) {|block| ... } ⇒ Object
extended
from Publisher
Subscribe to events.
-
.trigger(event_id, payload = EMPTY_HASH) ⇒ Object
extended
from Publisher
Trigger an event.
Instance Method Summary collapse
-
#register_event(id, info = EMPTY_HASH) ⇒ Object
Register an event.
Class Method Details
.event_bus(id) ⇒ Notifications::EventBus
Build an event bus
178 179 180 |
# File 'core/lib/rom/support/notifications.rb', line 178 def self.event_bus(id) EventBus.new(id, events: events.dup, listeners: listeners.dup) end |
.events ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
163 164 165 |
# File 'core/lib/rom/support/notifications.rb', line 163 def self.events @__events__ ||= {} end |
.listeners ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
168 169 170 |
# File 'core/lib/rom/support/notifications.rb', line 168 def self.listeners @__listeners__ ||= LISTENERS_HASH.dup end |
.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
Instance Method Details
#register_event(id, info = EMPTY_HASH) ⇒ Object
Register an event
158 159 160 |
# File 'core/lib/rom/support/notifications.rb', line 158 def register_event(id, info = EMPTY_HASH) Notifications.events[id] = Event.new(id, info) end |