Rails-8-API-Image-Processing / lib /coverage_baseline.rb
denise-oneill-inbox-ru's picture
D8 staging from 92665ef4298ecff6735b080ff7901f2c19f719a7 (part 2)
38367b5 verified
Raw History Blame Contribute Delete
930 Bytes
# frozen_string_literal: true
require "yaml"
require "json"
module CoverageBaseline
Result = Data.define(:line, :branch)
def self.below?(current:, baseline:)
current.line < baseline.line || current.branch < baseline.branch
end
def self.load_baseline(path)
data = YAML.load_file(path, aliases: true)
unless data.is_a?(Hash) && data.key?("line") && data.key?("branch")
raise ArgumentError, "missing required coverage keys: 'line' and 'branch' in #{path}"
end
Result.new(line: data.fetch("line").to_f, branch: data.fetch("branch").to_f)
end
def self.load_last_run(path)
data = JSON.parse(File.read(path))
result = data["result"]
unless result.is_a?(Hash) && result.key?("line") && result.key?("branch")
raise ArgumentError, "missing result in coverage data: #{path}"
end
Result.new(line: result.fetch("line").to_f, branch: result.fetch("branch").to_f)
end
end