class Quality::Runner

Knows how to run different quality tools based on a configuration already determined.

Public Class Methods

new(config, gem_spec: Gem::Specification, quality_checker_class: Quality::QualityChecker, count_io: IO, count_file: File, globber: Dir, which: Which.new) click to toggle source
# File lib/quality/runner.rb, line 24
def initialize(config, gem_spec: Gem::Specification,
               quality_checker_class: Quality::QualityChecker,
               count_io: IO, count_file: File,
               globber: Dir, which: Which.new)
  @config = config
  @gem_spec = gem_spec
  @quality_checker_class = quality_checker_class
  @count_io = count_io
  @count_file = count_file
  @globber = globber
  @which = which
end

Public Instance Methods

command_name(clazz, name) click to toggle source
# File lib/quality/runner.rb, line 79
def command_name(clazz, name)
  if clazz.respond_to? :command_name
    clazz.command_name
  else
    name
  end
end
count_existing_violations(filename) click to toggle source
# File lib/quality/runner.rb, line 72
def count_existing_violations(filename)
  existing_violations = @count_io.read(filename).to_i
  raise("Problem with file #{filename}") if existing_violations.negative?

  existing_violations
end
minimum_threshold_for(cmd) click to toggle source
# File lib/quality/runner.rb, line 97
def minimum_threshold_for(cmd)
  @config.minimum_threshold[cmd.to_sym] || 0
end
ratchet_quality_cmd(cmd, command_options, &count_violations_on_line) click to toggle source
# File lib/quality/runner.rb, line 101
def ratchet_quality_cmd(cmd,
                        command_options,
                        &count_violations_on_line)
  quality_checker = @quality_checker_class.new(cmd,
                                               command_options,
                                               @config.output_dir,
                                               @config.verbose,
                                               minimum_threshold_for(cmd))
  quality_checker.execute(&count_violations_on_line)
end
run_quality() click to toggle source
# File lib/quality/runner.rb, line 37
def run_quality
  tools.each do |tool_name, tool_exe, clazz|
    run_quality_with_tool(tool_name, tool_exe, clazz)
  end
end
run_quality_with_tool(tool_name, tool_exe, clazz) click to toggle source
# File lib/quality/runner.rb, line 43
def run_quality_with_tool(tool_name, tool_exe, clazz)
  suppressed = @config.skip_tools.include? tool_name
  installed = @gem_spec.find_all_by_name(tool_name).any? ||
              !@which.which(tool_exe).nil?

  if installed && !suppressed
    clazz.new(self).method("quality_#{tool_name}".to_sym).call
  elsif !installed
    puts "#{tool_name} not installed"
  end
end
run_ratchet() click to toggle source
# File lib/quality/runner.rb, line 55
def run_ratchet
  @config.all_output_files.each { |filename| run_ratchet_on_file(filename) }
end
run_ratchet_on_file(filename) click to toggle source
# File lib/quality/runner.rb, line 59
def run_ratchet_on_file(filename)
  puts "Processing #{filename}"
  existing_violations = count_existing_violations(filename)
  new_violations = [0, existing_violations - 1].max
  write_violations(filename, new_violations)
end
tools() click to toggle source
# File lib/quality/runner.rb, line 87
def tools
  TOOL_CLASSES.symbols_and_classes.map do |_symbol, clazz|
    clazz_name = clazz.to_s
    raise unless clazz_name.start_with?('Quality::Tools::')

    name = clazz_name.split('::').last.underscore
    [name, command_name(clazz, name), clazz]
  end.compact
end
write_violations(filename, new_violations) click to toggle source
# File lib/quality/runner.rb, line 66
def write_violations(filename, new_violations)
  @count_file.open(filename, 'w') do |file|
    file.write(new_violations.to_s + "\n")
  end
end