Sha256: 76eb7f641f09cfea75b76623961eb26ab70f13ab359984ef14bb2567ca5ac036
Contents?: true
Size: 1.38 KB
Versions: 3
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true module CottonTail module DSL # This is the top level DSL for defining the bindings and message routing of # a cotton App class Routes attr_reader :queues def initialize(queue_strategy:, connection:) @queue_strategy = queue_strategy @connection = connection @queues = {} end def draw(&block) instance_eval(&block) end # Define a new queue def queue(name, **opts, &block) @queue_strategy.call(name: name, connection: @connection, **opts).tap do |queue_instance| @queues[name] = queue_instance queue_dsl = Queue.new(name, queue_instance, self) queue_dsl.instance_eval(&block) if block_given? end end # 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 def topic(routing_prefix, &block) topic = Topic.new(routing_prefix, self) topic.instance_eval(&block) end def handle(key, handler = nil, &block) handler ||= block handlers[key] = handler end def handlers @handlers ||= {} end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cotton-tail-0.4.1 | lib/cotton_tail/dsl/routes.rb |
cotton-tail-0.4.0 | lib/cotton_tail/dsl/routes.rb |
cotton-tail-0.3.0 | lib/cotton_tail/dsl/routes.rb |