Class: Tango::ETL::Dispatcher
- Inherits:
-
Object
- Object
- Tango::ETL::Dispatcher
- Defined in:
- lib/tango/etl/dispatcher.rb
Overview
Dispatcher of handlers
Instance Method Summary collapse
-
#find_handler(url) ⇒ HandlerInterface
Find first applicable handler.
-
#initialize ⇒ Dispatcher
constructor
A new instance of Dispatcher.
-
#register(handler_class) ⇒ Dispatcher
Register new handler.
Constructor Details
#initialize ⇒ Dispatcher
Returns a new instance of Dispatcher.
9 10 11 |
# File 'lib/tango/etl/dispatcher.rb', line 9 def initialize @handlers = [] end |
Instance Method Details
#find_handler(url) ⇒ HandlerInterface
Find first applicable handler
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tango/etl/dispatcher.rb', line 35 def find_handler( url ) # Iterate handlers to find first matching handler @handlers.each do |h| return h if h.applicable?( url ) end nil end |
#register(handler_class) ⇒ Dispatcher
Register new handler
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tango/etl/dispatcher.rb', line 17 def register( handler_class ) # handler must implement HandlerInterface unless handler_class.ancestors.include? Tango::ETL::HandlerInterface raise "Handler must implement HandlerInterface" end # Append handler to container @handlers << handler_class self # Chainabilty! end |