Sha256: d08f2267323dd8518148030e7cee4e0cd7eff940bf324827c5936049d2cacb6b

Contents?: true

Size: 1.63 KB

Versions: 15

Compression:

Stored size: 1.63 KB

Contents

module RequestLogAnalyzer::Tracker

  # const_missing: this function is used to load subclasses in the RequestLogAnalyzer::Track namespace.
  # It will automatically load the required file based on the class name
  def self.const_missing(const)
    RequestLogAnalyzer::load_default_class_file(self, const)
  end

  # Base Tracker class. All other trackers inherit from this class
  #
  # Accepts the following options:
  # * <tt>:line_type</tt> The line type that contains the duration field (determined by the category proc).
  # * <tt>:if</tt> Proc that has to return !nil for a request to be passed to the tracker.
  # * <tt>:output</tt> Direct output here (defaults to STDOUT)
  #
  # For example :if => lambda { |request| request[:duration] && request[:duration] > 1.0 }
  class Base
    
    attr_reader :options
    
    def initialize(options ={})
      @options = options
    end
    
    def prepare
    end
    
    def update(request)
    end
    
    def finalize
    end
    
    def should_update?(request)
      return false if options[:line_type] && !request.has_line_type?(options[:line_type])
      
      if options[:if].kind_of?(Symbol)
        return false unless request[options[:if]]
      elsif options[:if].respond_to?(:call)
        return false unless options[:if].call(request)
      end
      
      if options[:unless].kind_of?(Symbol)
        return false if request[options[:unless]]
      elsif options[:unless].respond_to?(:call)
        return false if options[:unless].call(request)
      end
      
      return true
    end
    
    def report(output)
      output << self.inspect
      output << "\n"  
    end
         
  end 
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
wvanbergen-request-log-analyzer-1.1.1 lib/request_log_analyzer/tracker.rb
wvanbergen-request-log-analyzer-1.1.2 lib/request_log_analyzer/tracker.rb
wvanbergen-request-log-analyzer-1.1.3 lib/request_log_analyzer/tracker.rb
wvanbergen-request-log-analyzer-1.1.4 lib/request_log_analyzer/tracker.rb
wvanbergen-request-log-analyzer-1.1.5.1 lib/request_log_analyzer/tracker.rb
wvanbergen-request-log-analyzer-1.1.6 lib/request_log_analyzer/tracker.rb
wvanbergen-request-log-analyzer-1.1.7 lib/request_log_analyzer/tracker.rb
wvanbergen-request-log-analyzer-1.2.0 lib/request_log_analyzer/tracker.rb
request-log-analyzer-1.1.2 lib/request_log_analyzer/tracker.rb
request-log-analyzer-1.1.1 lib/request_log_analyzer/tracker.rb
request-log-analyzer-1.2.0 lib/request_log_analyzer/tracker.rb
request-log-analyzer-1.1.6 lib/request_log_analyzer/tracker.rb
request-log-analyzer-1.1.5.1 lib/request_log_analyzer/tracker.rb
request-log-analyzer-1.1.4 lib/request_log_analyzer/tracker.rb
request-log-analyzer-1.1.3 lib/request_log_analyzer/tracker.rb