class Rack::Tracker::HandlerSet
Constants
- Handler
Public Class Methods
new(&block)
click to toggle source
# File lib/rack/tracker.rb, line 82 def initialize(&block) @handlers = [] instance_exec(&block) if block_given? end
Public Instance Methods
each(env = {}, &block)
click to toggle source
# File lib/rack/tracker.rb, line 102 def each(env = {}, &block) @handlers.map { |h| h.init(env) }.each(&block) end
handler(name, configuration = {}, &block)
click to toggle source
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
# File lib/rack/tracker.rb, line 95 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