Sha256: 51e8f59aac8e81f7d29a26d50d9c6ceb0b92bb9bea6151b37313adfd91dde2d5

Contents?: true

Size: 935 Bytes

Versions: 8

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

module Stenotype
  #
  # {Stenotype::Dispatcher} is responsible for gluing together
  # publishing targets and data gathering.
  #
  class Dispatcher
    #
    # Publishes an event to the list of configured targets.
    #
    # @example Manually dispatching an event
    #   event = Stenotype::Event.new(data, options, eval_context)
    #   Stenotype::Dispatcher.new.publish(event)
    #
    # @param event {Stenotype::Event} An instance of event to be published.
    # @param serializer {#serialize} A class responsible for serializing the event
    # @return {Stenotype::Dispatcher} for the sake of chaining
    #
    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

    private

    def targets
      Stenotype.config.targets
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stenotype-0.1.19 lib/stenotype/dispatcher.rb
stenotype-0.1.17 lib/stenotype/dispatcher.rb
stenotype-0.1.16 lib/stenotype/dispatcher.rb
stenotype-0.1.15 lib/stenotype/dispatcher.rb
stenotype-0.1.13 lib/stenotype/dispatcher.rb
stenotype-0.1.12 lib/stenotype/dispatcher.rb
stenotype-0.1.10 lib/stenotype/dispatcher.rb
stenotype-0.1.9 lib/stenotype/dispatcher.rb