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)
-
+ (Object) included(base)
Extends base with ClassMethods.
Instance Method Summary (collapse)
-
- (self) bind_event(event_name, cb_proc)
Binds a
Proc
to be invoked when the givenevent_name
is triggered. -
- ({Symbol => Array<Proc>}) event_callbacks
Returns a hash of event names mapped to arrays of proc callbacks.
-
- (Object) trigger_event(event_name, *args)
Triggers an event by the given name, passing along any additional
args
as parameters to the callback.
Class Method Details
+ (Object) included(base)
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
- (self) bind_event(event_name, cb_proc)
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 |
- ({Symbol => Array<Proc>}) event_callbacks
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 |
- (Object) trigger_event(event_name, *args)
Triggers an event by the given name, passing along any additional
args
as parameters to the callback
29 30 31 32 33 34 35 36 37 |
# File 'lib/onstomp/interfaces/event_manager.rb', line 29 def trigger_event(event_name, *args) event_callbacks[event_name].each do |cb| begin cb.call(*args) rescue Exception => ex warn "[OnStomp/Event] triggering #{event_name} raised an error: #{ex}" end end end |