Class: RouteGuard::Formatter::Terminal
- Inherits:
-
Object
- Object
- RouteGuard::Formatter::Terminal
- Defined in:
- lib/route_guard/formatter/terminal.rb
Instance Attribute Summary collapse
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #format(report, io = $stdout) ⇒ Object
-
#initialize(verbose: false) ⇒ Terminal
constructor
A new instance of Terminal.
Constructor Details
#initialize(verbose: false) ⇒ Terminal
Returns a new instance of Terminal.
11 12 13 |
# File 'lib/route_guard/formatter/terminal.rb', line 11 def initialize(verbose: false) @verbose = verbose end |
Instance Attribute Details
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
9 10 11 |
# File 'lib/route_guard/formatter/terminal.rb', line 9 def verbose @verbose end |
Instance Method Details
#format(report, io = $stdout) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/route_guard/formatter/terminal.rb', line 15 def format(report, io = $stdout) io.puts Rainbow("─" * 50).faint io.puts Rainbow("RouteGuard").bold.cyan io.puts "Analyzing Rails Routes..." io.puts "#{report.routes.length} routes loaded" io.puts "Running #{Configuration::ALL_RULES.length} inspections..." io.puts Configuration::ALL_RULES.each do |rule| issues_for_rule = report.issues.select { |i| i.rule_name == rule } if rule == :statistics || rule == :complexity io.puts " #{Rainbow("✓").green} #{rule_display_name(rule)}" elsif issues_for_rule.any? { |i| i.severity == :error } io.puts " #{Rainbow("✗").red} #{rule_display_name(rule)}" elsif issues_for_rule.any? { |i| i.severity == :warning } io.puts " #{Rainbow("⚠").yellow} #{rule_display_name(rule)}" else io.puts " #{Rainbow("✓").green} #{rule_display_name(rule)}" end end io.puts Rainbow("─" * 50).faint if report.issues.any? io.puts Rainbow("Issues Found").bold.yellow io.puts report.issues.each do |issue| severity_color = issue.severity == :error ? :red : :yellow severity_prefix = issue.severity == :error ? "✗ Error" : "⚠ Warning" io.puts Rainbow("#{severity_prefix} [#{rule_display_name(issue.rule_name)}]:").bold.send(severity_color) io.puts " #{issue.}" if issue.route io.puts " Route: #{Rainbow(issue.route.to_s).bold}" end if issue.file && issue.line io.puts " Location: #{Rainbow(issue.location).underline}" end if issue..any? io.puts " Related Route(s):" issue..each do |rel| io.puts " - #{Rainbow(rel.to_s).bold} at #{Rainbow(rel.location).underline}" end end io.puts end io.puts Rainbow("─" * 50).faint else io.puts Rainbow("✓ No issues found! Your routes look excellent.").green.bold io.puts end # Summary io.puts Rainbow("Summary").bold.cyan io.puts " %-15s %d" % ["Routes", report.routes.length] io.puts " %-15s %d" % ["Errors", report.errors.length] io.puts " %-15s %d" % ["Warnings", report.warnings.length] health_color = if report.complexity_score >= 90 :green elsif report.complexity_score >= 70 :yellow else :red end io.puts " %-15s %s" % ["Health", Rainbow("#{report.complexity_score} / 100").bold.send(health_color)] io.puts " %-15s %.3f seconds" % ["Duration", report.duration] io.puts Rainbow("─" * 50).faint end |