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:
-
:ifProc that has to return !nil for a request to be passed to the tracker. -
:line_typeThe line type that contains the duration field (determined by the category proc). -
:outputDirect output here (defaults to STDOUT) -
:unlessProc 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
-
:ifHandle request if this proc is true for the handled request. -
:unlessHandle request if this proc is false for the handled request. -
:line_typeLine type this tracker will accept.
22 23 24 25 |
# File 'lib/request_log_analyzer/tracker.rb', line 22 def initialize( = {}) @options = setup_should_update_checks! end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/request_log_analyzer/tracker.rb', line 12 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.
39 40 41 42 43 44 45 |
# File 'lib/request_log_analyzer/tracker.rb', line 39 def create_lambda(arg) case arg when Proc then arg when Symbol then lambda { |request| request[arg] } else fail "Canot create a lambda expression from this argument: #{arg.inspect}!" end end |
#finalize ⇒ Object
Hook things that need to be done after running here.
57 58 |
# File 'lib/request_log_analyzer/tracker.rb', line 57 def finalize end |
#prepare ⇒ Object
Hook things that need to be done before running here.
48 49 |
# File 'lib/request_log_analyzer/tracker.rb', line 48 def prepare end |
#report(output) ⇒ Object
Hook report generation here. Defaults to self.inspect output The output object the report will be passed to.
77 78 79 80 |
# File 'lib/request_log_analyzer/tracker.rb', line 77 def report(output) output << inspect output << "\n" end |
#setup_should_update_checks! ⇒ Object
Sets up the tracker’s should_update? checks.
28 29 30 31 32 33 34 35 |
# File 'lib/request_log_analyzer/tracker.rb', line 28 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].is_a?(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].is_a?(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.
70 71 72 |
# File 'lib/request_log_analyzer/tracker.rb', line 70 def should_update?(request) @should_update_checks.all? { |c| c.call(request) } end |
#title ⇒ Object
The title of this tracker. Used for reporting.
83 84 85 |
# File 'lib/request_log_analyzer/tracker.rb', line 83 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.
89 90 91 |
# File 'lib/request_log_analyzer/tracker.rb', line 89 def to_yaml_object nil end |
#update(_request) ⇒ Object
Will be called with each request. request The request to track data in.
53 54 |
# File 'lib/request_log_analyzer/tracker.rb', line 53 def update(_request) end |