class Eventception::ImmutableDispatcher
Attributes
dispatcher[R]
Public Class Methods
new(listeners: [], subscribers: [])
click to toggle source
Creates an unmodifiable proxy for an event dispatcher.
Parameters:¶ ↑
- listeners
-
Array of event listeners
- subscribers
-
Array of event subscribers
Returns:¶ ↑
Nil
# File lib/eventception/immutable_dispatcher.rb, line 41 def initialize(listeners: [], subscribers: []) @dispatcher = Eventception::Dispatcher.new listeners.each do |listener| dispatcher.add_listener( event_name: listener.fetch(:event_name), listener: listener.fetch(:listener), listener_method: listener.fetch(:listener_method), priority: listener.fetch(:priority, 0), ) end subscribers.each { |subscriber| dispatcher.add_subscriber(subscriber: subscriber) } nil end
Public Instance Methods
dispatch(event_name:, event: Eventception::Event.new)
click to toggle source
Dispatches an event to all registered listeners.
Parameters:¶ ↑
- event_name
-
The name of the event to dispatch. The name of the event is the name of the method that is invoked on listeners.
- event
-
The event to pass to the event handlers/listeners If not supplied, an empty
Event
instance is created.
Returns:¶ ↑
The Event.
# File lib/eventception/immutable_dispatcher.rb, line 72 def dispatch(event_name:, event: Eventception::Event.new) dispatcher.dispatch(event_name: event_name, event: event) event end
listeners()
click to toggle source
listeners?()
click to toggle source
listeners_for(event_name:)
click to toggle source
Gets all listeners for the specific event sorted by descending priority.
Parameters:¶ ↑
- event_name
-
The name of the event
Returns:¶ ↑
The event listeners for the specific event sorted by descending priority.
# File lib/eventception/immutable_dispatcher.rb, line 105 def listeners_for(event_name:) dispatcher.listeners_for(event_name: event_name) end
listeners_for?(event_name:)
click to toggle source