Class: Stenotype::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/stenotype/dispatcher.rb

Overview

Dispatcher is responsible for gluing together publishing targets and data gathering.

Instance Method Summary collapse

Instance Method Details

#publish(event, serializer: Stenotype::EventSerializer) ⇒ Stenotype::Dispatcher

Publishes an event to the list of configured targets.

Examples:

Manually dispatching an event

event = Stenotype::Event.new(data, options, eval_context)
Stenotype::Dispatcher.new.publish(event)

Parameters:

  • event (Stenotype::Event)

    An instance of event to be published.

  • serializer (#serialize) (defaults to: Stenotype::EventSerializer)

    A class responsible for serializing the event

Returns:



20
21
22
23
24
25
26
27
28
# File 'lib/stenotype/dispatcher.rb', line 20

def publish(event, serializer: Stenotype::EventSerializer)
  event_data = serializer.new(event).serialize

  targets.each do |t|
    t.publish(event_data.to_json)
  end

  self
end