Sha256: a7ba19de939692bf01daa2339dd32fc6b3a2f09c73d48865926332507f3b7e6d

Contents?: true

Size: 953 Bytes

Versions: 25

Compression:

Stored size: 953 Bytes

Contents

# This class is responsible for dispatching the messages to the appropriate handler.
# The handlers must be registered with the dispatcher.
# Tha handlers need to be modules that implement the process method.
# What handler to dispatch the message to is figured out from the subject of the message.

require 'forwardable'

module DispatchRider
  class Dispatcher
    extend Forwardable

    attr_reader :handler_registrar

    def_delegators :handler_registrar, :register, :fetch, :unregister

    def initialize
      @handler_registrar = Registrars::Handler.new
    end

    def dispatch(message)
      callbacks.invoke(:dispatch_message, message) do
        handler_registrar.fetch(message.subject).new.do_process(message)
      end
      true # success => true (delete message)
    end

    private

    def config
      DispatchRider.config
    end

    def callbacks
      @callbacks ||= Callbacks::Access.new(config.callbacks)
    end

  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
dispatch-rider-1.4.2 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.4.0 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.3.6 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.3.5 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.3.4 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.3.3 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.3.2 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.3.1 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.3.0 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.11 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.10 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.9 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.8 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.7 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.6 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.5 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.4 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.3 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.2 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.2.1 lib/dispatch-rider/dispatcher.rb