Class: Hermes::EventHandler
- Inherits:
-
Object
- Object
- Hermes::EventHandler
- Defined in:
- lib/hermes/event_handler.rb
Defined Under Namespace
Classes: Registration
Instance Method Summary collapse
- #handle(event_class, with:, async: true, rpc: false, consumer_config: -> {}) ⇒ Object
- #handle_events(&block) ⇒ Object
-
#initialize(container: Dry::Container.new, consumer_builder: Hermes::DependenciesContainer["consumer_builder"]) ⇒ EventHandler
constructor
A new instance of EventHandler.
- #registration_for(event_class) ⇒ Object
Constructor Details
#initialize(container: Dry::Container.new, consumer_builder: Hermes::DependenciesContainer["consumer_builder"]) ⇒ EventHandler
Returns a new instance of EventHandler.
8 9 10 11 |
# File 'lib/hermes/event_handler.rb', line 8 def initialize(container: Dry::Container.new, consumer_builder: Hermes::DependenciesContainer["consumer_builder"]) @container = container @consumer_builder = consumer_builder end |
Instance Method Details
#handle(event_class, with:, async: true, rpc: false, consumer_config: -> {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hermes/event_handler.rb', line 17 def handle(event_class, with:, async: true, rpc: false, consumer_config: -> {}) handler = with = { async: async, rpc: rpc, consumer_config: consumer_config } consumer = build_consumer_for_event(event_class, consumer_config) Registration.new(handler, consumer, ).tap do |registration| container.register(event_class, registration) end end |
#handle_events(&block) ⇒ Object
13 14 15 |
# File 'lib/hermes/event_handler.rb', line 13 def handle_events(&block) instance_exec(&block) end |
#registration_for(event_class) ⇒ Object
31 32 33 |
# File 'lib/hermes/event_handler.rb', line 31 def registration_for(event_class) container.resolve(event_class) end |