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)
-
- (HandlerInterface) find_handler(url)
Find first applicable handler.
-
- (Dispatcher) initialize
constructor
A new instance of Dispatcher.
-
- (Dispatcher) register(handler_class)
Register new handler.
Constructor Details
- (Dispatcher) initialize
Returns a new instance of Dispatcher
9 10 11 |
# File 'lib/tango/etl/dispatcher.rb', line 9 def initialize @handlers = [] end |
Instance Method Details
- (HandlerInterface) find_handler(url)
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 |
- (Dispatcher) register(handler_class)
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 |