Class: Quality::Runner
- Inherits:
-
Object
- Object
- Quality::Runner
- Extended by:
- Forwardable
- Defined in:
- lib/quality/runner.rb
Overview
Knows how to run different quality tools based on a configuration already determined.
Instance Method Summary collapse
- #count_existing_violations(filename) ⇒ Object
-
#initialize(config, gem_spec: Gem::Specification, quality_checker_class: Quality::QualityChecker, count_io: IO, count_file: File, globber: Dir, which: Which.new) ⇒ Runner
constructor
A new instance of Runner.
- #ratchet_quality_cmd(cmd, command_options, &count_violations_on_line) ⇒ Object
- #run_quality ⇒ Object
- #run_quality_with_tool(tool_name, tool_exe) ⇒ Object
- #run_ratchet ⇒ Object
- #run_ratchet_on_file(filename) ⇒ Object
- #tools ⇒ Object
- #write_violations(filename, new_violations) ⇒ Object
Constructor Details
#initialize(config, gem_spec: Gem::Specification, quality_checker_class: Quality::QualityChecker, count_io: IO, count_file: File, globber: Dir, which: Which.new) ⇒ Runner
Returns a new instance of Runner.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/quality/runner.rb', line 22 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 |
Instance Method Details
#count_existing_violations(filename) ⇒ Object
73 74 75 76 77 |
# File 'lib/quality/runner.rb', line 73 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 |
#ratchet_quality_cmd(cmd, command_options, &count_violations_on_line) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/quality/runner.rb', line 93 def ratchet_quality_cmd(cmd, , &count_violations_on_line) quality_checker = @quality_checker_class.new(cmd, , @config.output_dir, @config.verbose) quality_checker.execute(&count_violations_on_line) end |
#run_quality ⇒ Object
38 39 40 41 42 |
# File 'lib/quality/runner.rb', line 38 def run_quality tools.each do |tool_name, tool_exe| run_quality_with_tool(tool_name, tool_exe) end end |
#run_quality_with_tool(tool_name, tool_exe) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/quality/runner.rb', line 44 def run_quality_with_tool(tool_name, tool_exe) 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 elsif !installed puts "#{tool_name} not installed" end end |
#run_ratchet ⇒ Object
56 57 58 |
# File 'lib/quality/runner.rb', line 56 def run_ratchet @config.all_output_files.each { |filename| run_ratchet_on_file(filename) } end |
#run_ratchet_on_file(filename) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/quality/runner.rb', line 60 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 ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/quality/runner.rb', line 79 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 command_name = if ancestor.respond_to? :command_name ancestor.command_name else name end [name, command_name] end.compact end |
#write_violations(filename, new_violations) ⇒ Object
67 68 69 70 71 |
# File 'lib/quality/runner.rb', line 67 def write_violations(filename, new_violations) @count_file.open(filename, 'w') do |file| file.write(new_violations.to_s + "\n") end end |