Symphony::

Routing

module
Extended With
Loggability

A mixin for adding handlers for multiple topic keys to a Task.

Public Class Methods

anchor
included( mod )

Add some instance data to inheriting +subclass+es.

# File lib/symphony/routing.rb, line 15
def self::included( mod )
        self.log.info "Adding routing to %p" % [ mod ]
        super
        mod.extend( Symphony::MethodUtilities )
        mod.extend( Symphony::Routing::ClassMethods )
        mod.singleton_attr_accessor( :routes, :route_options )
        mod.routes = Hash.new {|h,k| h[k] = [] }
        mod.route_options = Hash.new {|h,k| h[k] = {} }
        mod.always_rebind( true )
end

Public Instance Methods

anchor
find_matching_blocks( key )

Return routing block whose patterns match the specified key.

# File lib/symphony/routing.rb, line 99
def find_matching_blocks( key )
        return self.class.routes.inject([]) do |accum, (re, re_blocks)|
                accum += re_blocks if re.match( key )
                accum
        end
end
anchor
work( payload, metadata )

Route the work based on the blocks registered with 'on'.

# File lib/symphony/routing.rb, line 85
def work( payload, metadata )
        key = metadata[:delivery_info].routing_key
        self.log.debug "Routing a %s message..." % [ key ]

        blocks = self.find_matching_blocks( key )

        self.log.debug "  calling %d block/s" % [ blocks.length ]
        return blocks.all? do |block|
                block.bind( self ).call( payload, metadata )
        end
end