Sha256: b39cf601f1bd4cbcca07e6865df003f416be235a8155dc8833d63deb00c15e3c

Contents?: true

Size: 996 Bytes

Versions: 2

Compression:

Stored size: 996 Bytes

Contents

module Koality
  module Reporter
    class RailsBestPractices < Base

      attr_reader :table

      def initialize
        @table = build_table
      end

      def report(errors)
        unless errors.count > 0
          report_success
          return
        end

        table.title = color("Rails Best Practices - #{errors.count} Errors", :bold)
        rows = grouped_errors(errors).map do |message, errors|
          info = "#{color(message, :red)}\n#{color(errors.first.url, :cyan)}\n"
          info << errors.map { |e| "  #{e.short_filename}:#{e.line_number}" }.join("\n")
          [info, errors.count]
        end

        rows.each do |row|
          table.add_row row
          table.add_row :separator unless row == rows.last
        end

        puts table
      end

      private

      def report_success
        puts color("Rails Best Practices - 0 Errors", :green)
      end

      def grouped_errors(errors)
        errors.group_by(&:message)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
koality-1.0.1 lib/koality/reporter/rails_best_practices.rb
koality-1.0.0 lib/koality/reporter/rails_best_practices.rb