Class: Stenotype::ContextHandlers::Collection
- Inherits:
-
Collectible::CollectionBase
- Object
- Collectible::CollectionBase
- Stenotype::ContextHandlers::Collection
- Defined in:
- lib/stenotype/context_handlers/collection.rb
Overview
A class representing a list of available context handlers
Instance Method Summary collapse
-
#choose(handler_name:) ⇒ #as_json
Return a handler with given handler_name if found in collection, raises if a handler is not registered.
-
#unregister(handler) ⇒ Stenotype::ContextHandlers::Collection
Removes a registered handler.
Instance Method Details
#choose(handler_name:) ⇒ #as_json
Return a handler with given handler_name if found in collection, raises if a handler is not registered
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/stenotype/context_handlers/collection.rb', line 48 def choose(handler_name:) handler = find_by(handler_name: handler_name) handler || raise( Stenotype::UnknownHandlerError, "Handler '#{handler_name}' is not found. "\ "Please make sure the handler you've specified is "\ "registered in the list of known handlers. "\ "See #{Stenotype::ContextHandlers} for more information.", ) end |
#unregister(handler) ⇒ Stenotype::ContextHandlers::Collection
TODO:
Add delete to the collectible delegation list
and then use alias_method :unregister, :delete
Removes a registered handler.
84 85 86 87 |
# File 'lib/stenotype/context_handlers/collection.rb', line 84 def unregister(handler) items.delete(handler) self end |