Class: Messaging::Routes
- Inherits:
-
Object
- Object
- Messaging::Routes
- Includes:
- Routing
- Defined in:
- lib/messaging/routes.rb
Overview
Public: Used by Messaging.routes to setup the routes for matching messages to callables
See routing.rb for more information.
Instance Method Summary collapse
-
#consumer(name, **options, &block) ⇒ Object
Creates a consumer for the default adapter.
- #consumers ⇒ Object
- #define_consumers! ⇒ Object
-
#draw(&block) ⇒ Object
Public: Evaluate route definition.
-
#reload_consumer_routes! ⇒ Object
Keeps the consumers, but reload their subscriptions so code reloading works.
Methods included from Routing
Instance Method Details
#consumer(name, **options, &block) ⇒ Object
Creates a consumer for the default adapter
11 12 13 |
# File 'lib/messaging/routes.rb', line 11 def consumer(name, **, &block) consumer_definitions[name] = { options: , block: block } end |
#consumers ⇒ Object
35 36 37 |
# File 'lib/messaging/routes.rb', line 35 def consumers @consumers ||= [] end |
#define_consumers! ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/messaging/routes.rb', line 15 def define_consumers! return unless consumers.empty? consumer_definitions.each do |name, definition| c = Messaging.consumer_adapter.create_consumer(name, definition.fetch(:options)) definition.fetch(:block)&.call(c) consumers << c end end |
#draw(&block) ⇒ Object
Public: Evaluate route definition.
40 41 42 |
# File 'lib/messaging/routes.rb', line 40 def draw(&block) instance_eval(&block) end |
#reload_consumer_routes! ⇒ Object
Keeps the consumers, but reload their subscriptions so code reloading works. The consumer has a reference to the class name of each of its handlers, if the handler is reloaded the reference would point to an old instance.
28 29 30 31 32 33 |
# File 'lib/messaging/routes.rb', line 28 def reload_consumer_routes! consumers.each do |c| c.clear_routes! consumer_definitions[c.name].fetch(:block)&.call(c) end end |