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



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

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.



23
24
25
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 23

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

Instance Attribute Details

#trackersObject (readonly)

Returns the value of attribute trackers.



4
5
6
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 4

def trackers
  @trackers
end

Instance Method Details

#initialize_copy(other) ⇒ Object

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



13
14
15
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 13

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

#reset!Object

Drop all trackers



18
19
20
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 18

def reset!
  @trackers = []
end

#track(tracker_klass, value_field = {}, other_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.



30
31
32
33
34
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 30

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