class CottonTail::DSL::Routes
This is the top level DSL
for defining the bindings and message routing of a cotton App
Attributes
queues[R]
Public Class Methods
new(queue_strategy:, connection:)
click to toggle source
# File lib/cotton_tail/dsl/routes.rb, line 10 def initialize(queue_strategy:, connection:) @queue_strategy = queue_strategy @connection = connection @queues = [] end
Public Instance Methods
draw(&block)
click to toggle source
# File lib/cotton_tail/dsl/routes.rb, line 16 def draw(&block) instance_eval(&block) end
handle(key, handler = nil, &block)
click to toggle source
# File lib/cotton_tail/dsl/routes.rb, line 44 def handle(key, handler = nil, &block) handler ||= block handlers[Route.new(key)] = handler end
handlers()
click to toggle source
# File lib/cotton_tail/dsl/routes.rb, line 49 def handlers @handlers ||= {} end
queue(name = '', **opts, &block)
click to toggle source
Define a new queue
# File lib/cotton_tail/dsl/routes.rb, line 21 def queue(name = '', **opts, &block) @queue_strategy.call(name: name, connection: @connection, **opts).tap do |queue_instance| @queues << queue_instance queue_dsl = Queue.new(name, queue_instance, self) queue_dsl.instance_eval(&block) if block_given? end end
topic(routing_prefix, &block)
click to toggle source
Creates a scope for nested bindings
@example
topic 'some.resource' do handle 'event.updated', lambda do puts "I'm bound to some.resource.event.updated" end end
@param [String] routing_prefix The first part of the routing_key
# File lib/cotton_tail/dsl/routes.rb, line 39 def topic(routing_prefix, &block) topic = Topic.new(routing_prefix, self) topic.instance_eval(&block) end