Class: Servus::Events::Router

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

Overview

Abstract base class for event routers.

Routers resolve which services should be invoked when an event fires. The Bus iterates all configured routers (in order), collects the Invocation objects they return, deduplicates by key, and executes.

Servus ships one built-in router — ClassRouter — which reads the invoke declarations from Event classes. Applications can add their own routers (e.g. a data-driven router backed by a database table) by subclassing Router and implementing #resolve.

Configure routers in the Servus initializer:

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

Direct Known Subclasses

ClassRouter

Instance Method Summary collapse

Instance Method Details

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

Resolves which service invocations should run for the given event.

Implementations must evaluate any conditions (if/unless) internally and return only invocations that will run. The Bus does not perform further filtering.

Parameters:

  • event_name (Symbol)

    the name of the emitted event

  • payload (Hash)

    the event payload

Returns:

Raises:

  • (NotImplementedError)

    when called on the abstract base class



39
40
41
# File 'lib/servus/events/router.rb', line 39

def resolve(event_name, payload)
  raise NotImplementedError, "#{self.class}#resolve must be implemented"
end