Class: Medi8::Registry
- Inherits:
-
Object
- Object
- Medi8::Registry
- Defined in:
- lib/medi8/registry.rb
Overview
Registry for managing request handlers and event notifications
Instance Method Summary collapse
-
#find_handler_for(request_class) ⇒ Object
Find the handler for a given request class.
-
#find_notification_handlers_for(event_class) ⇒ Object
Find all handlers for a given notification event class.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(request_class, handler_class) ⇒ Object
Singleton instance of the Registry.
-
#register_notification(event_class, handler_class, async: false) ⇒ Object
Register a notification event and its handler.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
6 7 8 |
# File 'lib/medi8/registry.rb', line 6 def initialize @handlers = {} end |
Instance Method Details
#find_handler_for(request_class) ⇒ Object
Find the handler for a given request class
16 17 18 |
# File 'lib/medi8/registry.rb', line 16 def find_handler_for(request_class) @handlers[request_class] end |
#find_notification_handlers_for(event_class) ⇒ Object
Find all handlers for a given notification event class
27 28 29 |
# File 'lib/medi8/registry.rb', line 27 def find_notification_handlers_for(event_class) (@notifications && @notifications[event_class]) || [] end |
#register(request_class, handler_class) ⇒ Object
Singleton instance of the Registry
11 12 13 |
# File 'lib/medi8/registry.rb', line 11 def register(request_class, handler_class) @handlers[request_class] = handler_class end |
#register_notification(event_class, handler_class, async: false) ⇒ Object
Register a notification event and its handler
21 22 23 24 |
# File 'lib/medi8/registry.rb', line 21 def register_notification(event_class, handler_class, async: false) @notifications ||= Hash.new { |h, k| h[k] = [] } @notifications[event_class] << [handler_class, async] end |