Class: QueueBus::Dispatchers
- Inherits:
-
Object
- Object
- QueueBus::Dispatchers
- Defined in:
- lib/queue_bus/dispatchers.rb
Overview
A collection of Dispatches
Each Dispatch is an application with it’s own set of subscriptions. This is a master object that provides some basic controls over the set of applications.
Instance Method Summary collapse
-
#dispatch(app_key = nil, &block) ⇒ Object
Fetches a dispatch for the application key and binds the provided block to it.
- #dispatcher_by_key(app_key) ⇒ Object
- #dispatcher_execute(app_key, key, attributes) ⇒ Object
- #dispatchers ⇒ Object
Instance Method Details
#dispatch(app_key = nil, &block) ⇒ Object
Fetches a dispatch for the application key and binds the provided block to it.
10 11 12 13 14 |
# File 'lib/queue_bus/dispatchers.rb', line 10 def dispatch(app_key = nil, &block) dispatcher = dispatcher_by_key(app_key) dispatcher.instance_eval(&block) dispatcher end |
#dispatcher_by_key(app_key) ⇒ Object
21 22 23 24 25 |
# File 'lib/queue_bus/dispatchers.rb', line 21 def dispatcher_by_key(app_key) app_key = Application.normalize(app_key || ::QueueBus.default_app_key) @dispatchers ||= {} @dispatchers[app_key] ||= Dispatch.new(app_key) end |
#dispatcher_execute(app_key, key, attributes) ⇒ Object
27 28 29 30 31 |
# File 'lib/queue_bus/dispatchers.rb', line 27 def dispatcher_execute(app_key, key, attributes) @dispatchers ||= {} dispatcher = @dispatchers[app_key] dispatcher&.execute(key, attributes) end |
#dispatchers ⇒ Object
16 17 18 19 |
# File 'lib/queue_bus/dispatchers.rb', line 16 def dispatchers @dispatchers ||= {} @dispatchers.values end |