Class: Bundler::Source::Rubygems::Remote
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/bundler/source/rubygems/remote.rb |
Constant Summary
-
MAX_CACHE_SLUG_HOST_SIZE =
private
# File 'lib/bundler/source/rubygems/remote.rb', line 34
255 minus dot minus MD5 length
255 - 1 - 32
Class Method Summary
- .new(uri, cooldown: nil) ⇒ Remote constructor
Instance Attribute Summary
- #anonymized_uri readonly
- #cooldown readonly
- #original_uri readonly
- #uri readonly
Instance Method Summary
- #cache_slug ⇒ String
-
#effective_cooldown
Returns the cooldown days that apply to this remote, resolving the precedence
::Bundler::CLI> config > Gemfile per-source and then raising the result to RubyGems' own setting. - #to_s
- #apply_auth(uri, auth) private
- #remove_auth(uri) private
Constructor Details
.new(uri, cooldown: nil) ⇒ Remote
# File 'lib/bundler/source/rubygems/remote.rb', line 9
def initialize(uri, cooldown: nil) orig_uri = uri uri = Bundler.settings.mirror_for(uri) @original_uri = orig_uri if orig_uri != uri fallback_auth = Bundler.settings.credentials_for(uri) @uri = apply_auth(uri, fallback_auth).freeze @anonymized_uri = remove_auth(@uri).freeze @cooldown = cooldown end
Instance Attribute Details
#anonymized_uri (readonly)
[ GitHub ]# File 'lib/bundler/source/rubygems/remote.rb', line 7
attr_reader :uri, :anonymized_uri, :original_uri, :cooldown
#cooldown (readonly)
[ GitHub ]# File 'lib/bundler/source/rubygems/remote.rb', line 7
attr_reader :uri, :anonymized_uri, :original_uri, :cooldown
#original_uri (readonly)
[ GitHub ]# File 'lib/bundler/source/rubygems/remote.rb', line 7
attr_reader :uri, :anonymized_uri, :original_uri, :cooldown
#uri (readonly)
[ GitHub ]# File 'lib/bundler/source/rubygems/remote.rb', line 7
attr_reader :uri, :anonymized_uri, :original_uri, :cooldown
Instance Method Details
#apply_auth(uri, auth) (private)
[ GitHub ]# File 'lib/bundler/source/rubygems/remote.rb', line 67
def apply_auth(uri, auth) if auth && uri.userinfo.nil? uri = uri.dup uri.userinfo = auth end uri rescue Gem::URI::InvalidComponentError = "Please CGI escape your usernames and passwords before " \ "setting them for authentication." raise HTTPError.new() end
#cache_slug ⇒ String
# File 'lib/bundler/source/rubygems/remote.rb', line 40
def cache_slug @cache_slug ||= begin return nil unless SharedHelpers.md5_available? cache_uri = original_uri || uri host = cache_uri.to_s.start_with?("file://") ? nil : cache_uri.host uri_parts = [host, cache_uri.user, cache_uri.port, cache_uri.path] uri_parts.compact! uri_digest = SharedHelpers.digest(:MD5).hexdigest(uri_parts.join(".")) uri_parts.pop host_parts = uri_parts.join(".") return uri_digest if host_parts.empty? shortened_host_parts = host_parts[0...MAX_CACHE_SLUG_HOST_SIZE] [shortened_host_parts, uri_digest].join(".") end end
#effective_cooldown
Returns the cooldown days that apply to this remote, resolving the
precedence ::Bundler::CLI > config > Gemfile per-source and then raising the
result to RubyGems' own setting. Returns nil if no cooldown applies.
The resolver asks once per candidate spec, so the settings lookup is
memoized. That snapshots the value: a Remote created before a
settings change keeps the old one. Nothing in ::Bundler changes the
cooldown setting after the sources are built (the ::Bundler::CLI flag is applied
before the ::Bundler::Definition exists), so build a new Remote if you need to.
# File 'lib/bundler/source/rubygems/remote.rb', line 29
def effective_cooldown return @effective_cooldown if defined?(@effective_cooldown) @effective_cooldown = Bundler.settings.cooldown_for(@cooldown) end
#remove_auth(uri) (private)
[ GitHub ]#to_s
[ GitHub ]# File 'lib/bundler/source/rubygems/remote.rb', line 61
def to_s "rubygems remote at #{anonymized_uri}" end