lib/request_log_analyzer/aggregator/summarizer.rb in request-log-analyzer-1.13.1 vs lib/request_log_analyzer/aggregator/summarizer.rb in request-log-analyzer-1.13.3

- old
+ new

@@ -1,11 +1,8 @@ module RequestLogAnalyzer::Aggregator - class Summarizer < Base - class Definer - attr_reader :trackers # Initialize tracker array def initialize @trackers = [] @@ -29,12 +26,12 @@ # Helper function to initialize a tracker and add it to the tracker array. # <tt>tracker_class</tt> The class to include # <tt>optiont</tt> The options to pass to the trackers. def track(tracker_klass, value_field = {}, other_options = {}) - options = value_field.kind_of?(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.kind_of?(Symbol) + 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 end attr_reader :trackers @@ -52,11 +49,11 @@ def setup end # Call prepare on all trackers. def prepare - raise "No trackers set up in Summarizer!" if @trackers.nil? || @trackers.empty? + fail 'No trackers set up in Summarizer!' if @trackers.nil? || @trackers.empty? @trackers.each { |tracker| tracker.prepare } end # Pass all requests to trackers and let them update if necessary. # <tt>request</tt> The request to pass. @@ -80,11 +77,11 @@ # Exports all the tracker results to YAML. It will call the to_yaml_object method # for every tracker and combines these into a single YAML export. def to_yaml require 'yaml' - trackers_export = @trackers.inject({}) do |export, tracker| + trackers_export = @trackers.reduce({}) do |export, tracker| export[tracker.title] = tracker.to_yaml_object; export end YAML.dump(trackers_export) end @@ -102,44 +99,44 @@ end # Generate report header. # <tt>output</tt> RequestLogAnalyzer::Output object to output to def report_header(output) - output.title("Request summary") + output.title('Request summary') - output.with_style(:cell_separator => false) do - output.table({:width => 20}, {:font => :bold}) do |rows| + output.with_style(cell_separator: false) do + output.table({ width: 20 }, { font: :bold }) do |rows| source.processed_files.each do |f| rows << ['Processed File:', f] end rows << ['Parsed lines:', source.parsed_lines] rows << ['Skipped lines:', source.skipped_lines] rows << ['Parsed requests:', source.parsed_requests] rows << ['Skipped requests:', source.skipped_requests] - rows << ["Warnings:", @warnings_encountered.map { |(key, value)| "#{key}: #{value}" }.join(', ')] if has_warnings? + rows << ['Warnings:', @warnings_encountered.map { |(key, value)| "#{key}: #{value}" }.join(', ')] if has_warnings? end end output << "\n" end # Generate report footer. # <tt>output</tt> RequestLogAnalyzer::Output object to output to def report_footer(output) if has_log_ordering_warnings? - output.title("Parse warnings") + output.title('Parse warnings') - output.puts "Parsable lines were encountered without a header line before it. It" - output.puts "could be that logging is not setup correctly for your application." - output.puts "Visit this website for logging configuration tips:" - output.puts output.link("http://github.com/wvanbergen/request-log-analyzer/wikis/configure-logging") + output.puts 'Parsable lines were encountered without a header line before it. It' + output.puts 'could be that logging is not setup correctly for your application.' + output.puts 'Visit this website for logging configuration tips:' + output.puts output.link('http://github.com/wvanbergen/request-log-analyzer/wikis/configure-logging') output.puts end end # Returns true if there were any warnings generated by the trackers def has_warnings? - @warnings_encountered.inject(0) { |result, (_, value)| result += value } > 0 + @warnings_encountered.reduce(0) { |result, (_, value)| result += value } > 0 end # Returns true if there were any log ordering warnings def has_log_ordering_warnings? @warnings_encountered[:no_current_request] && @warnings_encountered[:no_current_request] > 0 @@ -147,10 +144,10 @@ # Store an encountered warning # <tt>type</tt> Type of warning # <tt>message</tt> Warning message # <tt>lineno</tt> The line on which the error was encountered - def warning(type, message, lineno) + def warning(type, _message, _lineno) @warnings_encountered[type] ||= 0 @warnings_encountered[type] += 1 end end end