Class: Tango::ETL::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/tango/etl/dispatcher.rb

Overview

Dispatcher of handlers

Author:

  • Mckomo

Instance Method Summary collapse

Constructor Details

#initializeDispatcher

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

Parameters:

  • url (String)

    URL of the page to be handled

Returns:



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

Parameters:

Returns:



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