class Emittance::Dispatcher

Abstract class for dispatchers. Subclasses must implement the following methods:

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

registrations[R]

Public Class Methods

clear_registrations!() click to toggle source

@return [RegistrationMap] the registrations

# File lib/emittance/dispatcher.rb, line 49
def clear_registrations!
  registrations.each_key { |key| clear_registrations_for! key }
  registrations
end
clear_registrations_for!(identifier) click to toggle source

@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
inherited(subklass) click to toggle source

@private

# File lib/emittance/dispatcher.rb, line 23
def inherited(subklass)
  subklass.instance_variable_set '@registrations', RegistrationMap.new
end
process_event(event) click to toggle source

Calls the subclass's _process_event method.

# File lib/emittance/dispatcher.rb, line 28
def process_event(event)
  _process_event(event)
end
register(identifier, params = {}, &callback) click to toggle source

Calls the subclass's _register method.

# File lib/emittance/dispatcher.rb, line 33
def register(identifier, params = {}, &callback)
  _register(identifier, params, &callback)
end
register_method_call(identifier, object, method_name, params = {}) click to toggle source

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
registrations_for(identifier) click to toggle source

@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

_process_event(_event) click to toggle source
# File lib/emittance/dispatcher.rb, line 64
def _process_event(_event)
  raise NotImplementedError
end
_register(_identifier, _params, &_callback) click to toggle source
# File lib/emittance/dispatcher.rb, line 68
def _register(_identifier, _params, &_callback)
  raise NotImplementedError
end
_register_method_call(_identifier, _object, _method_name, _params) click to toggle source
# File lib/emittance/dispatcher.rb, line 72
def _register_method_call(_identifier, _object, _method_name, _params)
  raise NotImplementedError
end