Sha256: 63ba1c860dd9265ee1b68671941c8081d89570c47f09755eb4ebae35b598626c

Contents?: true

Size: 927 Bytes

Versions: 7

Compression:

Stored size: 927 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)
      end

      self
    end

    private

    def targets
      Stenotype.config.targets
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
stenotype-0.1.8 lib/stenotype/dispatcher.rb
stenotype-0.1.7 lib/stenotype/dispatcher.rb
stenotype-0.1.6 lib/stenotype/dispatcher.rb
stenotype-0.1.5 lib/stenotype/dispatcher.rb
stenotype-0.1.4 lib/stenotype/dispatcher.rb
stenotype-0.1.2 lib/stenotype/dispatcher.rb
stenotype-0.1.1 lib/stenotype/dispatcher.rb