Class: Rack::Tracker::HandlerSet
- Inherits:
-
Object
- Object
- Rack::Tracker::HandlerSet
- Defined in:
- lib/rack/tracker.rb
Defined Under Namespace
Classes: Handler
Instance Method Summary collapse
- #each(env = {}, &block) ⇒ Object
-
#handler(name, configuration = {}, &block) ⇒ Object
setup the handler class with configuration options and make it ready for receiving the env during injection.
-
#initialize(&block) ⇒ HandlerSet
constructor
A new instance of HandlerSet.
Constructor Details
#initialize(&block) ⇒ HandlerSet
79 80 81 82 |
# File 'lib/rack/tracker.rb', line 79 def initialize(&block) @handlers = [] instance_exec(&block) if block_given? end |
Instance Method Details
#each(env = {}, &block) ⇒ Object
99 100 101 |
# File 'lib/rack/tracker.rb', line 99 def each(env = {}, &block) @handlers.map { |h| h.init(env) }.each(&block) end |
#handler(name, configuration = {}, &block) ⇒ Object
setup the handler class with configuration options and make it ready for receiving the env during injection
usage:
use Rack::Tracker do
handler :google_analytics, { tracker: 'U-XXXXX-Y' }
end
92 93 94 95 96 97 |
# File 'lib/rack/tracker.rb', line 92 def handler(name, configuration = {}, &block) # we need here "something" (which is atm the handler struct) # to postpone the initialization of the handler, # to give it the env and configuration options when the result of the handler is injected into the response. @handlers << Handler.new(Rack::Tracker::HandlerDelegator.handler(name), configuration) end |