Class: Koality::Reporter::RailsBestPractices

Inherits:
Base
  • Object
show all
Defined in:
lib/koality/reporter/rails_best_practices.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

start

Constructor Details

#initializeRailsBestPractices

Returns a new instance of RailsBestPractices.



7
8
9
# File 'lib/koality/reporter/rails_best_practices.rb', line 7

def initialize
  @table = build_table
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



5
6
7
# File 'lib/koality/reporter/rails_best_practices.rb', line 5

def table
  @table
end

Instance Method Details

#report(errors) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/koality/reporter/rails_best_practices.rb', line 11

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