lib/quality/runner.rb in quality-32.1.1 vs lib/quality/runner.rb in quality-33.0.0
- old
+ new
@@ -2,10 +2,11 @@
require 'active_support/inflector'
require 'forwardable'
require_relative 'which'
require_relative 'directory_of_classes'
+require_relative 'tool'
# Quality is a tool that runs quality checks on Ruby code using cane,
# reek, flog, flay and rubocop and makes sure your numbers don't get
# any worse over time.
module Quality
@@ -16,12 +17,10 @@
TOOL_CLASSES.require_classes
# Knows how to run different quality tools based on a configuration
# already determined.
class Runner
- TOOL_CLASSES.symbols_and_classes.each { |_symbol, clazz| include clazz }
-
extend ::Forwardable
def initialize(config, gem_spec: Gem::Specification,
quality_checker_class: Quality::QualityChecker,
count_io: IO, count_file: File,
@@ -34,22 +33,22 @@
@globber = globber
@which = which
end
def run_quality
- tools.each do |tool_name, tool_exe|
- run_quality_with_tool(tool_name, tool_exe)
+ tools.each do |tool_name, tool_exe, clazz|
+ run_quality_with_tool(tool_name, tool_exe, clazz)
end
end
- def run_quality_with_tool(tool_name, tool_exe)
+ 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
- method("quality_#{tool_name}".to_sym).call
+ clazz.new(self).method("quality_#{tool_name}".to_sym).call
elsif !installed
puts "#{tool_name} not installed"
end
end
@@ -71,26 +70,28 @@
end
def count_existing_violations(filename)
existing_violations = @count_io.read(filename).to_i
raise("Problem with file #{filename}") if existing_violations < 0
+
existing_violations
end
- def command_name(ancestor, name)
- if ancestor.respond_to? :command_name
- ancestor.command_name
+ def command_name(clazz, name)
+ if clazz.respond_to? :command_name
+ clazz.command_name
else
name
end
end
def tools
- self.class.ancestors.map do |ancestor|
- ancestor_name = ancestor.to_s
- next unless ancestor_name.start_with?('Quality::Tools::')
- name = ancestor.to_s.split('::').last.underscore
- [name, command_name(ancestor, name)]
+ 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
def minimum_threshold_for(cmd)
@config.minimum_threshold[cmd.to_sym] || 0