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
40 41 42 43 44 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 40 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
25 26 27 28 29 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 25 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
18 19 20 21 22 23 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 18 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
9 10 11 12 13 14 15 16 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 9 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
31 32 33 34 35 36 37 38 |
# File 'lib/spm_version_updates/fail_on_threshold.rb', line 31 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(ArgumentError, "#{input_name} must be false, true, major, minor, or patch") end |