lib/request_log_analyzer/controller.rb in request-log-analyzer-1.1.0 vs lib/request_log_analyzer/controller.rb in request-log-analyzer-1.1.1

- old
+ new

@@ -60,11 +60,11 @@ end else options.store(:source_files, arguments.parameters) end - controller = Controller.new(RequestLogAnalyzer::Source::LogFile.new(file_format, options), options) + controller = Controller.new(RequestLogAnalyzer::Source::LogParser.new(file_format, options), options) options[:assume_correct_order] = arguments[:assume_correct_order] # register filters if arguments[:after] || arguments[:before] @@ -145,28 +145,20 @@ end end # Adds an aggregator to the controller. The aggregator will be called for every request # that is parsed from the provided sources (see add_source) - def add_aggregator(agg) - if agg.kind_of?(Symbol) - require File.dirname(__FILE__) + "/aggregator/#{agg}" - agg = RequestLogAnalyzer::Aggregator.const_get(agg.to_s.split(/[^a-z0-9]/i).map{ |w| w.capitalize }.join('')) - end - + def add_aggregator(agg) + agg = RequestLogAnalyzer::Aggregator.const_get(RequestLogAnalyzer::to_camelcase(agg)) if agg.kind_of?(Symbol) @aggregators << agg.new(@source, @options) end alias :>> :add_aggregator # Adds a request filter to the controller. def add_filter(filter, filter_options = {}) - if filter.kind_of?(Symbol) - require File.dirname(__FILE__) + "/filter/#{filter}" - filter = RequestLogAnalyzer::Filter.const_get(filter.to_s.split(/[^a-z0-9]/i).map{ |w| w.capitalize }.join('')) - end - + filter = RequestLogAnalyzer::Filter.const_get(RequestLogAnalyzer::to_camelcase(filter)) if filter.kind_of?(Symbol) @filters << filter.new(file_format, @options.merge(filter_options)) end # Runs RequestLogAnalyzer # 1. Call prepare on every aggregator @@ -176,17 +168,15 @@ # 4. Call finalize on every aggregator # 5. Call report on every aggregator # 6. Finalize Source def run! - - @filters.each { |filter| filter.prepare } @aggregators.each { |agg| agg.prepare } begin - @source.requests do |request| + @source.each_request do |request| @filters.each { |filter| request = filter.filter(request) } @aggregators.each { |agg| agg.aggregate(request) } if request end rescue Interrupt => e handle_progress(:interrupted) @@ -199,10 +189,15 @@ @aggregators.each { |agg| agg.report(@output) } @output.footer @source.finalize - + if @output.io.kind_of?(File) + puts + puts "Report written to: " + File.expand_path(@output.io.path) + puts "Thanks for using request-log-analyzer!" + @output.io.close + end end end end