Class: CottonTail::DSL::Routes
- Inherits:
-
Object
- Object
- CottonTail::DSL::Routes
- Defined in:
- lib/cotton_tail/dsl/routes.rb
Overview
This is the top level DSL for defining the bindings and message routing of a cotton App
Instance Attribute Summary collapse
-
#queues ⇒ Object
readonly
Returns the value of attribute queues.
Instance Method Summary collapse
- #draw(&block) ⇒ Object
- #handle(key, handler = nil, &block) ⇒ Object
- #handlers ⇒ Object
-
#initialize(queue_strategy:, connection:) ⇒ Routes
constructor
A new instance of Routes.
-
#queue(name, **opts, &block) ⇒ Object
Define a new queue.
-
#topic(routing_prefix, &block) ⇒ Object
Creates a scope for nested bindings.
Constructor Details
#initialize(queue_strategy:, connection:) ⇒ Routes
Returns a new instance of Routes.
10 11 12 13 14 |
# File 'lib/cotton_tail/dsl/routes.rb', line 10 def initialize(queue_strategy:, connection:) @queue_strategy = queue_strategy @connection = connection @queues = {} end |
Instance Attribute Details
#queues ⇒ Object (readonly)
Returns the value of attribute queues.
8 9 10 |
# File 'lib/cotton_tail/dsl/routes.rb', line 8 def queues @queues end |
Instance Method Details
#draw(&block) ⇒ Object
16 17 18 |
# File 'lib/cotton_tail/dsl/routes.rb', line 16 def draw(&block) instance_eval(&block) end |
#handle(key, handler = nil, &block) ⇒ Object
44 45 46 47 |
# File 'lib/cotton_tail/dsl/routes.rb', line 44 def handle(key, handler = nil, &block) handler ||= block handlers[key] = handler end |
#handlers ⇒ Object
49 50 51 |
# File 'lib/cotton_tail/dsl/routes.rb', line 49 def handlers @handlers ||= {} end |
#queue(name, **opts, &block) ⇒ Object
Define a new queue
21 22 23 24 25 26 27 |
# 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[name] = queue_instance queue_dsl = Queue.new(name, queue_instance, self) queue_dsl.instance_eval(&block) if block_given? end end |
#topic(routing_prefix, &block) ⇒ Object
Creates a scope for nested bindings
39 40 41 42 |
# 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 |