Sha256: 3243b262c1ae9f8af92ad3c93ac6a612b71ef8f11049d0e2bcded1e7fcd28a1d

Contents?: true

Size: 834 Bytes

Versions: 18

Compression:

Stored size: 834 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

    include Callbacks::Support

    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


  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dispatch-rider-1.9.0 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.8.6 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.8.5 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.8.4 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.8.3 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.8.2 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.8.1 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.8.0 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.7.2 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.7.1 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.7.0 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.6.2 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.6.1 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.6.0 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.5.3 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.5.2 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.5.1 lib/dispatch-rider/dispatcher.rb
dispatch-rider-1.5.0 lib/dispatch-rider/dispatcher.rb