module RequestLogAnalyzer::Tracker
# const_missing: this function is used to load subclasses in the RequestLogAnalyzer::Track namespace.
# It will automatically load the required file based on the class name
def self.const_missing(const)
RequestLogAnalyzer::load_default_class_file(self, const)
end
# Base Tracker class. All other trackers inherit from this class
#
# Accepts the following options:
# * :line_type The line type that contains the duration field (determined by the category proc).
# * :if Proc that has to return !nil for a request to be passed to the tracker.
# * :output Direct output here (defaults to STDOUT)
#
# For example :if => lambda { |request| request[:duration] && request[:duration] > 1.0 }
class Base
attr_reader :options
def initialize(options ={})
@options = options
end
def prepare
end
def update(request)
end
def finalize
end
def should_update?(request)
return false if options[:line_type] && !request.has_line_type?(options[:line_type])
if options[:if].kind_of?(Symbol)
return false unless request[options[:if]]
elsif options[:if].respond_to?(:call)
return false unless options[:if].call(request)
end
if options[:unless].kind_of?(Symbol)
return false if request[options[:unless]]
elsif options[:unless].respond_to?(:call)
return false if options[:unless].call(request)
end
return true
end
def report(output)
output << self.inspect
output << "\n"
end
end
end