class Emittance::Dispatcher
Abstract class for dispatchers. Subclasses must implement the following methods:
-
._process_event
-
._register
-
._register_method_call
These methods can be private. These methods will have access to .registrations_for
, which takes an identifier and returns an enumerable object with each object registered to that identifier. These objects can be anything you want, but typically represent the callback you would like to run whenever an event of a certain type is emitted.
Attributes
Public Class Methods
@return [RegistrationMap] the registrations
# File lib/emittance/dispatcher.rb, line 49 def clear_registrations! registrations.each_key { |key| clear_registrations_for! key } registrations end
@param identifier the identifier the registrations for hwich you would like to clear @return [RegistrationCollectionProxy] the cleared registration proxy
# File lib/emittance/dispatcher.rb, line 56 def clear_registrations_for!(identifier) registrations_for(identifier).clear end
@private
# File lib/emittance/dispatcher.rb, line 23 def inherited(subklass) subklass.instance_variable_set '@registrations', RegistrationMap.new end
Calls the subclass's _process_event
method.
# File lib/emittance/dispatcher.rb, line 28 def process_event(event) _process_event(event) end
Calls the subclass's _register
method.
# File lib/emittance/dispatcher.rb, line 33 def register(identifier, params = {}, &callback) _register(identifier, params, &callback) end
Calls the subclass's _register_method_call
method.
# File lib/emittance/dispatcher.rb, line 38 def register_method_call(identifier, object, method_name, params = {}) _register_method_call(identifier, object, method_name, params) end
@param identifier the identifier the registrations for which you would like to look up @return [RegistrationCollectionProxy] an enumerable containing all registrations for a given identifier
# File lib/emittance/dispatcher.rb, line 44 def registrations_for(identifier) registrations[identifier] end
Private Class Methods
# File lib/emittance/dispatcher.rb, line 64 def _process_event(_event) raise NotImplementedError end
# File lib/emittance/dispatcher.rb, line 68 def _register(_identifier, _params, &_callback) raise NotImplementedError end
# File lib/emittance/dispatcher.rb, line 72 def _register_method_call(_identifier, _object, _method_name, _params) raise NotImplementedError end