Module: FailOnThreshold

Defined in:
lib/spm_version_updates/fail_on_threshold.rb

Overview

Parses fail-on inputs and evaluates whether reported updates should fail.

Constant Summary collapse

ANY =
"any"

Class Method Summary collapse

Class Method Details

.build_message(threshold, count) ⇒ Object



36
37
38
39
40
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 36

def self.build_message(threshold, count)
  plural = count == 1 ? "" : "s"
  threshold_note = threshold == ANY ? "" : " #{threshold}+"
  "Found #{count}#{threshold_note} SPM dependency update#{plural}"
end

.failure_count(threshold, reporter) ⇒ Object



21
22
23
24
25
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 21

def self.failure_count(threshold, reporter)
  return reporter.records.size if threshold == ANY

  UpdateSeverity.count_at_or_above(reporter.severity_counts, threshold)
end

.failure_message(threshold, reporter) ⇒ Object



14
15
16
17
18
19
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 14

def self.failure_message(threshold, reporter)
  return nil unless threshold

  count = failure_count(threshold, reporter)
  count.positive? ? build_message(threshold, count) : nil
end

.from_input(value) ⇒ Object



10
11
12
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 10

def self.from_input(value)
  normalize(value)
end

.normalize(value) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 27

def self.normalize(value)
  normalized = value.to_s.strip.downcase
  return nil if ["", "false", "none"].include?(normalized)
  return ANY if ["true", ANY].include?(normalized)
  return normalized if UpdateSeverity.threshold?(normalized)

  raise(SpmVersionUpdates::ConfigurationError, "fail-on must be false, true, any, major, minor, or patch")
end