class RequestLogAnalyzer::Tracker::Base

Base Tracker class. All other trackers inherit from this class

Accepts the following options:

For example :if => lambda { |request| request && request > 1.0 }

Attributes

options[R]

Public Class Methods

new(options = {}) click to toggle source

Initialize the class Note that the options are only applicable if should_update? is not overwritten by the inheriting class.

Options

  • :if Handle request if this proc is true for the handled request.

  • :unless Handle request if this proc is false for the handled request.

  • :line_type Line type this tracker will accept.

   # File lib/request_log_analyzer/tracker.rb
22 def initialize(options = {})
23   @options = options
24   setup_should_update_checks!
25 end

Public Instance Methods

create_lambda(arg) click to toggle source

Creates a lambda expression to return a static field from a request. If the argument already is a lambda exprssion, it will simply return the argument.

   # File lib/request_log_analyzer/tracker.rb
39 def create_lambda(arg)
40   case arg
41   when Proc   then arg
42   when Symbol then lambda { |request| request[arg] }
43   else fail "Canot create a lambda expression from this argument: #{arg.inspect}!"
44   end
45 end
finalize() click to toggle source

Hook things that need to be done after running here.

   # File lib/request_log_analyzer/tracker.rb
57 def finalize
58 end
prepare() click to toggle source

Hook things that need to be done before running here.

   # File lib/request_log_analyzer/tracker.rb
48 def prepare
49 end
report(output) click to toggle source

Hook report generation here. Defaults to self.inspect output The output object the report will be passed to.

   # File lib/request_log_analyzer/tracker.rb
77 def report(output)
78   output << inspect
79   output << "\n"
80 end
setup_should_update_checks!() click to toggle source

Sets up the tracker’s should_update? checks.

   # File lib/request_log_analyzer/tracker.rb
28 def setup_should_update_checks!
29   @should_update_checks = []
30   @should_update_checks.push(lambda { |request| request.has_line_type?(options[:line_type]) }) if options[:line_type]
31   @should_update_checks.push(options[:if]) if options[:if].respond_to?(:call)
32   @should_update_checks.push(lambda { |request| request[options[:if]] }) if options[:if].is_a?(Symbol)
33   @should_update_checks.push(lambda { |request| !options[:unless].call(request) }) if options[:unless].respond_to?(:call)
34   @should_update_checks.push(lambda { |request| !request[options[:unless]] }) if options[:unless].is_a?(Symbol)
35 end
should_update?(request) click to toggle source

Determine if we should run the update function at all. Usually the update function will be heavy, so a light check is done here determining if we need to call update at all.

Default this checks if defined:

* :line_type is also in the request hash.
* :if is true for this request.
* :unless if false for this request

request The request object.

   # File lib/request_log_analyzer/tracker.rb
70 def should_update?(request)
71   @should_update_checks.all? { |c| c.call(request) }
72 end
title() click to toggle source

The title of this tracker. Used for reporting.

   # File lib/request_log_analyzer/tracker.rb
83 def title
84   self.class.to_s
85 end
to_yaml_object() click to toggle source

This method is called by RequestLogAnalyzer::Aggregator:Summarizer to retrieve an object with all the results of this tracker, that can be dumped to YAML format.

   # File lib/request_log_analyzer/tracker.rb
89 def to_yaml_object
90   nil
91 end
update(_request) click to toggle source

Will be called with each request. request The request to track data in.

   # File lib/request_log_analyzer/tracker.rb
53 def update(_request)
54 end