class Emque::Consuming::Router::Mapping
Attributes
consumer[RW]
mapping[RW]
middleware[RW]
topic[RW]
workers[RW]
Public Class Methods
new(mapping, &block)
click to toggle source
# File lib/emque/consuming/router.rb, line 65 def initialize(mapping, &block) self.topic = mapping.keys.first self.workers = mapping.fetch(:workers, 1) self.consumer = mapping.values.first self.mapping = {} self.middleware = [] mapping.fetch(:middleware, []).map(&:use) self.instance_eval(&block) end
Public Instance Methods
map(map)
click to toggle source
# File lib/emque/consuming/router.rb, line 76 def map(map) mapping.merge!(map) end
middleware?()
click to toggle source
# File lib/emque/consuming/router.rb, line 80 def middleware? middleware.count > 0 end
route(type)
click to toggle source
# File lib/emque/consuming/router.rb, line 84 def route(type) mapping[type] end
use(callable)
click to toggle source
# File lib/emque/consuming/router.rb, line 88 def use(callable) unless callable.respond_to?(:call) and callable.arity == 1 raise( ConfigurationError, "#{self.class.name}#use must receive a callable object with an " + "arity of one." ) end middleware << callable end