Module: Gem::CooldownSettings
| Relationships & Source Files | |
| Defined in: | lib/rubygems/cooldown_settings.rb |
Overview
The rules RubyGems and Bundler share for reading a configured cooldown period. Bundler ships a copy of this file, so it deliberately has no requires: none of the rest of RubyGems is guaranteed to be around it.
Class Method Summary
-
.combine(*values)
The cooldown that applies when RubyGems and Bundler are configured separately: the longest of
values, so a cooldown configured for only one of the two tools protects both. -
.days(value)
valueread as a number of days, or nil when it is absent or cannot be read as a non-negative integer. -
.invalid?(value) ⇒ Boolean
True when
valueis configured but cannot be read as a number of days. -
.invalid_message(value, source)
Internal use only
sourcenames where the value came from, since RubyGems and Bundler now each read the other's setting and the same complaint from either of them is otherwise impossible to trace back to a file.
Class Method Details
.combine(*values)
The cooldown that applies when RubyGems and Bundler are configured
separately: the longest of values, so a cooldown configured for only
one of the two tools protects both. Returns nil when none of them is
usable.
A configured 0 takes part like any other value rather than switching the cooldown off, which leaves --cooldown 0 as the way to bypass a cooldown that the other tool configures.
# File 'lib/rubygems/cooldown_settings.rb', line 45
def self.combine(*values) values.filter_map {|value| days(value) }.max end
.days(value)
value read as a number of days, or nil when it is absent or cannot be
read as a non-negative integer. A gemrc entry and a Bundler config entry
are both arbitrary YAML, so either can be any type at all.
# File 'lib/rubygems/cooldown_settings.rb', line 18
def self.days(value) return if value.nil? # Base 10 explicitly: a leading zero is how a user writes a small number # of days, not a request for octal. days = Integer(value.to_s, 10, exception: false) days if days && !days.negative? end
.invalid?(value) ⇒ Boolean
True when value is configured but cannot be read as a number of days.
# File 'lib/rubygems/cooldown_settings.rb', line 31
def self.invalid?(value) !value.nil? && days(value).nil? end
.invalid_message(value, source)
source names where the value came from, since RubyGems and Bundler now
each read the other's setting and the same complaint from either of them
is otherwise impossible to trace back to a file.
# File 'lib/rubygems/cooldown_settings.rb', line 53
def self.(value, source) # :nodoc: "Invalid cooldown value #{value.inspect} in #{source}, so it is ignored. " \ "Expected a non-negative integer number of days." end