class CC::Analyzer::Formatters::PlainTextFormatter

Public Instance Methods

engine_running(engine, &block) click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 39
def engine_running(engine, &block)
  super(engine) do
    result = with_spinner("Running #{current_engine.name}: ", &block)
    if result.skipped?
      puts(colorize("Skipped #{current_engine.name}: #{result.stderr}", :yellow))
    end
  end
end
failed(output) click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 48
def failed(output)
  spinner.stop("Failed")
  puts colorize("\nAnalysis failed with the following output:", :red)
  puts output
  exit 1
end
finished() click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 13
def finished
  puts

  issues_by_path.each do |path, file_issues|
    puts colorize("== #{path} (#{pluralize(file_issues.size, "issue")}) ==", :yellow)

    IssueSorter.new(file_issues).by_location.each do |issue|
      if (location = issue["location"])
        source_buffer = @filesystem.source_buffer_for(location["path"])
        print(colorize(LocationDescription.new(source_buffer, location, ": "), :cyan))
      end

      print(issue["description"])
      print(colorize(" [#{issue["engine_name"]}]", "#333333"))
      puts
    end
    puts
  end

  print(colorize("Analysis complete! Found #{pluralize(issues.size, "issue")}", :green))
  unless warnings.empty?
    print(colorize(" and #{pluralize(warnings.size, "warning")}", :green))
  end
  puts(colorize(".", :green))
end
started() click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 9
def started
  puts colorize("Starting analysis", :green)
end

Private Instance Methods

colorize(string, *args) click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 69
def colorize(string, *args)
  rainbow.wrap(string).color(*args)
end
issues() click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 79
def issues
  @issues ||= []
end
issues_by_path() click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 83
def issues_by_path
  issues.group_by { |i| i["location"]["path"] }.sort
end
measurements() click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 91
def measurements
  @measurements ||= []
end
pluralize(number, noun) click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 95
def pluralize(number, noun)
  "#{ActiveSupport::NumberHelper.number_to_delimited(number)} #{noun.pluralize(number)}"
end
rainbow() click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 73
def rainbow
  @rainbow ||= Rainbow.new.tap do |rainbow|
    rainbow.enabled = false unless @output.tty?
  end
end
spinner(text = nil) click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 57
def spinner(text = nil)
  @spinner ||= Spinner.new(text)
end
warnings() click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 87
def warnings
  @warnings ||= []
end
with_spinner(text) { || ... } click to toggle source
# File lib/cc/analyzer/formatters/plain_text_formatter.rb, line 61
def with_spinner(text)
  spinner(text).start
  yield
ensure
  spinner.stop
  @spinner = nil
end