Module: OnStomp::Interfaces::EventManager
- Included in:
- Failover::FailoverEvents, ClientEvents, ConnectionEvents
- Defined in:
- lib/onstomp/interfaces/event_manager.rb
Overview
Mixin for event management.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Extends base with ClassMethods.
Instance Method Summary collapse
-
#bind_event(event_name, cb_proc) ⇒ self
Binds a
Proc
to be invoked when the givenevent_name
is triggered. -
#event_callbacks ⇒ {Symbol => Array<Proc>}
Returns a hash of event names mapped to arrays of proc callbacks.
-
#trigger_event(event_name, *args) ⇒ Object
Triggers an event by the given name, passing along any additional
args
as parameters to the callback.
Class Method Details
.included(base) ⇒ Object
Extends base with ClassMethods
6 7 8 |
# File 'lib/onstomp/interfaces/event_manager.rb', line 6 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#bind_event(event_name, cb_proc) ⇒ self
Binds a Proc
to be invoked when the given event_name
is triggered.
14 15 16 17 |
# File 'lib/onstomp/interfaces/event_manager.rb', line 14 def bind_event(event_name, cb_proc) event_callbacks[event_name] << cb_proc self end |
#event_callbacks ⇒ {Symbol => Array<Proc>}
Returns a hash of event names mapped to arrays of proc callbacks.
21 22 23 |
# File 'lib/onstomp/interfaces/event_manager.rb', line 21 def event_callbacks @event_callbacks ||= Hash.new { |h, k| h[k] = [] } end |
#trigger_event(event_name, *args) ⇒ Object
Triggers an event by the given name, passing along any additional args
as parameters to the callback
29 30 31 |
# File 'lib/onstomp/interfaces/event_manager.rb', line 29 def trigger_event(event_name, *args) event_callbacks[event_name].each { |cb| cb.call(*args) } end |