Class: Familia::Connection::ResponsibilityChain
- Inherits:
-
Object
- Object
- Familia::Connection::ResponsibilityChain
- Defined in:
- lib/familia/connection/handlers.rb
Overview
Manages ordered chain of connection handlers
NOTE: It is important that the last handler in a responsibility chain
either always provides a connection or raises an error. Otherwise the
end result will simply be nil without any guidance to the caller.
Instance Method Summary collapse
- #add_handler(handler) ⇒ Object
- #handle(uri) ⇒ Object
-
#initialize ⇒ ResponsibilityChain
constructor
A new instance of ResponsibilityChain.
Constructor Details
#initialize ⇒ ResponsibilityChain
Returns a new instance of ResponsibilityChain.
16 17 18 |
# File 'lib/familia/connection/handlers.rb', line 16 def initialize @handlers = [] end |
Instance Method Details
#add_handler(handler) ⇒ Object
20 21 22 23 |
# File 'lib/familia/connection/handlers.rb', line 20 def add_handler(handler) @handlers << handler self end |
#handle(uri) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/familia/connection/handlers.rb', line 25 def handle(uri) @handlers.each do |handler| connection = handler.handle(uri) if connection Fiber[:familia_connection_handler_class] = handler.class return connection end end # If we get here, no handler provided a connection nil end |