Class: RequestLogAnalyzer::Tracker::Base
- Inherits:
-
Object
- Object
- RequestLogAnalyzer::Tracker::Base
- Defined in:
- lib/request_log_analyzer/tracker.rb
Overview
Base Tracker class. All other trackers inherit from this class
Accepts the following options:
-
:if
Proc that has to return !nil for a request to be passed to the tracker. -
:line_type
The line type that contains the duration field (determined by the category proc). -
:output
Direct output here (defaults to STDOUT) -
:unless
Proc that has to return nil for a request to be passed to the tracker.
For example :if => lambda { |request| request && request > 1.0 }
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#create_lambda(arg) ⇒ Object
Creates a lambda expression to return a static field from a request.
-
#finalize ⇒ Object
Hook things that need to be done after running here.
-
#initialize(options = {}) ⇒ Base
constructor
Initialize the class Note that the options are only applicable if should_update? is not overwritten by the inheriting class.
-
#prepare ⇒ Object
Hook things that need to be done before running here.
-
#report(output) ⇒ Object
Hook report generation here.
-
#setup_should_update_checks! ⇒ Object
Sets up the tracker’s should_update? checks.
-
#should_update?(request) ⇒ Boolean
Determine if we should run the update function at all.
-
#title ⇒ Object
The title of this tracker.
-
#to_yaml_object ⇒ Object
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.
-
#update(request) ⇒ Object
Will be called with each request.
Constructor Details
#initialize(options = {}) ⇒ Base
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.
30 31 32 33 |
# File 'lib/request_log_analyzer/tracker.rb', line 30 def initialize( ={}) @options = setup_should_update_checks! end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/request_log_analyzer/tracker.rb', line 20 def @options end |
Instance Method Details
#create_lambda(arg) ⇒ Object
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.
47 48 49 50 51 52 53 |
# File 'lib/request_log_analyzer/tracker.rb', line 47 def create_lambda(arg) case arg when Proc then arg when Symbol then lambda { |request| request[arg] } else raise "Canot create a lambda expression from this argument: #{arg.inspect}!" end end |
#finalize ⇒ Object
Hook things that need to be done after running here.
65 66 |
# File 'lib/request_log_analyzer/tracker.rb', line 65 def finalize end |
#prepare ⇒ Object
Hook things that need to be done before running here.
56 57 |
# File 'lib/request_log_analyzer/tracker.rb', line 56 def prepare end |
#report(output) ⇒ Object
Hook report generation here. Defaults to self.inspect output
The output object the report will be passed to.
85 86 87 88 |
# File 'lib/request_log_analyzer/tracker.rb', line 85 def report(output) output << self.inspect output << "\n" end |
#setup_should_update_checks! ⇒ Object
Sets up the tracker’s should_update? checks.
36 37 38 39 40 41 42 43 |
# File 'lib/request_log_analyzer/tracker.rb', line 36 def setup_should_update_checks! @should_update_checks = [] @should_update_checks.push( lambda { |request| request.has_line_type?([:line_type]) } ) if [:line_type] @should_update_checks.push([:if]) if [:if].respond_to?(:call) @should_update_checks.push( lambda { |request| request[[:if]] }) if [:if].kind_of?(Symbol) @should_update_checks.push( lambda { |request| ![:unless].call(request) }) if [:unless].respond_to?(:call) @should_update_checks.push( lambda { |request| !request[[:unless]] }) if [:unless].kind_of?(Symbol) end |
#should_update?(request) ⇒ Boolean
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.
78 79 80 |
# File 'lib/request_log_analyzer/tracker.rb', line 78 def should_update?(request) @should_update_checks.all? { |c| c.call(request) } end |
#title ⇒ Object
The title of this tracker. Used for reporting.
91 92 93 |
# File 'lib/request_log_analyzer/tracker.rb', line 91 def title self.class.to_s end |
#to_yaml_object ⇒ Object
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.
97 98 99 |
# File 'lib/request_log_analyzer/tracker.rb', line 97 def to_yaml_object nil end |
#update(request) ⇒ Object
Will be called with each request. request
The request to track data in.
61 62 |
# File 'lib/request_log_analyzer/tracker.rb', line 61 def update(request) end |