lib/quality/quality_checker.rb in quality-36.1.0 vs lib/quality/quality_checker.rb in quality-37.0.0

- old
+ new

@@ -1,10 +1,11 @@ # frozen_string_literal: true require_relative 'command_output_processor' require_relative 'process' require_relative 'ruby_spawn' +require_relative 'threshold' module Quality # Runs a quality-checking, command, checks it agaist the existing # number of violations for that command, and decreases that number # if possible, or outputs data if the number of violations increased. @@ -26,11 +27,14 @@ @count_dir = count_dir @cmd = cmd @command_options = command_options @verbose = verbose @count_dir.mkdir(output_dir) unless @count_file.exists?(output_dir) - @filename = File.join(output_dir, "#{cmd}_high_water_mark") + @threshold = Quality::Threshold.new(cmd, + count_io: count_io, + count_file: count_file, + output_dir: output_dir) @process_class = process_class end def execute(&count_violations_on_line) processor, exit_status = process_command(&count_violations_on_line) @@ -68,18 +72,11 @@ end MAX_VIOLATIONS = 9_999_999_999 def existing_violations - @existing_violations ||= - begin - if @count_file.exist?(@filename) - @count_io.read(@filename).to_i - else - MAX_VIOLATIONS - end - end + @existing_violations ||= (@threshold.threshold || MAX_VIOLATIONS) end def rendered_full_cmd full_cmd.scan(/.{1,78}/).join("\\\n") end @@ -124,11 +121,9 @@ @found_output = false RubySpawn.new(@cmd, args).invocation end def write_violations(new_violations) - @count_file.open(@filename, 'w') do |file| - file.write(new_violations.to_s + "\n") - end + @threshold.write_violations(new_violations) end end end