module ROM::Notifications
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.
@example
class Setup extend ROM::Notifications register_event('setup.before_setup') register_event('setup.after_setup') def initialize @bus = Notifications.event_bus(:setup) end def setup @bus.trigger('setup.before_setup', at: Time.now) # ... @bus.trigger('setup.after_setup', at: Time.now) end end class Plugin extend ROM::Notifications::Listener subscribe('setup.after_setup') do |event| puts "Loaded at #{event.at.iso8601}" end end
Constants
- LISTENERS_HASH
Public Class Methods
event_bus(id)
click to toggle source
Build an event bus
@param [Symbol] id Bus key @return [Notifications::EventBus] A new bus
@api public
# File lib/rom/support/notifications.rb, line 180 def self.event_bus(id) EventBus.new(id, events: events.dup, listeners: listeners.dup) end
events()
click to toggle source
@api private
# File lib/rom/support/notifications.rb, line 165 def self.events @__events__ ||= {} end
listeners()
click to toggle source
@api private
# File lib/rom/support/notifications.rb, line 170 def self.listeners @__listeners__ ||= LISTENERS_HASH.dup end
Public Instance Methods
register_event(id, info = EMPTY_HASH)
click to toggle source
Register an event
@param [String] id A unique event key @param [Hash] info
@api public
# File lib/rom/support/notifications.rb, line 160 def register_event(id, info = EMPTY_HASH) Notifications.events[id] = Event.new(id, info) end