lib/request_log_analyzer/tracker.rb in request-log-analyzer-1.3.5 vs lib/request_log_analyzer/tracker.rb in request-log-analyzer-1.3.6

- old
+ new

@@ -27,12 +27,23 @@ # * <tt>:if</tt> Handle request if this proc is true for the handled request. # * <tt>:unless</tt> Handle request if this proc is false for the handled request. # * <tt>:line_type</tt> Line type this tracker will accept. def initialize(options ={}) @options = options + setup_should_update_checks! end + # Sets up the tracker's should_update? checks. + def setup_should_update_checks! + @should_update_checks = [] + @should_update_checks.push( lambda { |request| request.has_line_type?(options[:line_type]) } ) if options[:line_type] + @should_update_checks.push(options[:if]) if options[:if].respond_to?(:call) + @should_update_checks.push( lambda { |request| request[options[:if]] }) if options[:if].kind_of?(Symbol) + @should_update_checks.push( lambda { |request| !options[:unless].call(request) }) if options[:unless].respond_to?(:call) + @should_update_checks.push( lambda { |request| !request[options[:unless]] }) if options[:unless].kind_of?(Symbol) + end + # Hook things that need to be done before running here. def prepare end # Will be called with each request. @@ -53,28 +64,10 @@ # * :if is true for this request. # * :unless if false for this request # # <tt>request</tt> The request object. def should_update?(request) - return false if options[:line_type] && !request.has_line_type?(options[:line_type]) - - if options[:if] - 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 - end - - if options[:unless] - 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 - end - - return true + @should_update_checks.all? { |c| c.call(request) } end # Hook report generation here. # Defaults to self.inspect # <tt>output</tt> The output object the report will be passed to. \ No newline at end of file