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
184 185 186 |
# File 'lib/rom/support/notifications.rb', line 184 def self.event_bus(id) EventBus.new(id, events: events.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.
169 170 171 |
# File 'lib/rom/support/notifications.rb', line 169 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.
174 175 176 |
# File 'lib/rom/support/notifications.rb', line 174 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
164 165 166 |
# File 'lib/rom/support/notifications.rb', line 164 def register_event(id, info = EMPTY_HASH) Notifications.events[id] = Event.new(id, info) end |