Class: Servus::Events::ClassRouter

Inherits:
Router
  • Object
show all
Defined in:
lib/servus/events/class_router.rb

Overview

Default router that reads invoke declarations from Event classes.

ClassRouter is what ships with Servus and is the default when no routers are configured. It resolves invocations by looking up all Event classes registered for the given event name and calling invocations_for on each — which evaluates if/unless conditions and returns Invocation objects for actions that should run.

Applications can add additional routers (e.g. a data-driven router backed by a database table) alongside the ClassRouter:

Servus.configure do |config|
  config.routers = [
    Servus::Events::ClassRouter.new,
    MyApp::DataDrivenRouter.new
  ]
end

See Also:

  • Router
  • Servus::Event#invocations_for

Instance Method Summary collapse

Instance Method Details

#resolve(event_name, payload) ⇒ Array<Servus::Events::Invocation>

Resolves invocations by reading invoke declarations from all Event classes registered for the given event name.

Parameters:

  • event_name (Symbol)

    the name of the emitted event

  • payload (Hash)

    the event payload

Returns:



32
33
34
35
36
37
# File 'lib/servus/events/class_router.rb', line 32

def resolve(event_name, payload)
  event_class = Bus.event_for(event_name)
  return [] unless event_class

  event_class.invocations_for(payload)
end