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
- .build_message(threshold, count) ⇒ Object
- .failure_count(threshold, reporter) ⇒ Object
- .failure_message(threshold, reporter) ⇒ Object
- .from_inputs(explicit_fail_on, legacy_fail_on) ⇒ Object
- .normalize(value, input_name) ⇒ Object
Class Method Details
.build_message(threshold, count) ⇒ Object
41 42 43 44 45 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 41 def self.(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
26 27 28 29 30 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 26 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
19 20 21 22 23 24 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 19 def self.(threshold, reporter) return nil unless threshold count = failure_count(threshold, reporter) count.positive? ? (threshold, count) : nil end |
.from_inputs(explicit_fail_on, legacy_fail_on) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 10 def self.from_inputs(explicit_fail_on, legacy_fail_on) input_name, value = [ ["fail-on", explicit_fail_on], ["fail-on-updates", legacy_fail_on], ["fail-on-updates", "false"], ].find { |_name, candidate| candidate } normalize(value, input_name) end |
.normalize(value, input_name) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 32 def self.normalize(value, input_name) normalized = value.downcase return nil if ["false", "none"].include?(normalized) return ANY if normalized == "true" return normalized if UpdateSeverity.threshold?(normalized) raise(SpmVersionUpdates::ConfigurationError, "#{input_name} must be false, true, major, minor, or patch") end |