Class: RequestLogAnalyzer::Aggregator::Summarizer::Definer

Inherits:
Object
  • Object
show all
Defined in:
lib/request_log_analyzer/aggregator/summarizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefiner

Initialize tracker array



10
11
12
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 10

def initialize
  @trackers = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(tracker_method, *args) ⇒ Object

Include missing trackers through method missing.



26
27
28
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 26

def method_missing(tracker_method, *args)
  track(tracker_method, *args)
end

Instance Attribute Details

#trackersObject (readonly)

Returns the value of attribute trackers.



7
8
9
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 7

def trackers
  @trackers
end

Instance Method Details

#duration(duration_field, options = {}) ⇒ Object

Track the duration of a specific category duration_field Field to track options options are passed to new frequency tracker



44
45
46
47
48
49
50
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 44

def duration(duration_field, options = {})
  if duration_field.kind_of?(Symbol)
    track(:duration, options.merge(:duration => duration_field))
  elsif duration_field.kind_of?(Hash)
    track(:duration, duration_field.merge(options))        
  end
end

#frequency(category_field, options = {}) ⇒ Object

Track the frequency of a specific category category_field Field to track options options are passed to new frequency tracker



33
34
35
36
37
38
39
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 33

def frequency(category_field, options = {})
  if category_field.kind_of?(Symbol)
    track(:frequency, options.merge(:category => category_field))
  elsif category_field.kind_of?(Hash)
    track(:frequency, category_field.merge(options))
  end
end

#initialize_copy(other) ⇒ Object

Initialize tracker summarizer by duping the trackers of another summarizer other The other Summarizer



16
17
18
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 16

def initialize_copy(other)
  @trackers = other.trackers.dup
end

#reset!Object

Drop all trackers



21
22
23
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 21

def reset!
  @trackers = []
end

#track(tracker_klass, options = {}) ⇒ Object

Helper function to initialize a tracker and add it to the tracker array. tracker_class The class to include optiont The options to pass to the trackers.



55
56
57
58
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 55

def track(tracker_klass, options = {})
  tracker_klass = RequestLogAnalyzer::Tracker.const_get(RequestLogAnalyzer::to_camelcase(tracker_klass)) if tracker_klass.kind_of?(Symbol)
  @trackers << tracker_klass.new(options)
end