Class: Bundler::Source::Rubygems::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/source/rubygems/remote.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, cooldown: nil) ⇒ Remote

Returns a new instance of Remote.



9
10
11
12
13
14
15
16
17
18
# 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_uriObject (readonly)

Returns the value of attribute anonymized_uri.



7
8
9
# File 'lib/bundler/source/rubygems/remote.rb', line 7

def anonymized_uri
  @anonymized_uri
end

#cooldownObject (readonly)

Returns the value of attribute cooldown.



7
8
9
# File 'lib/bundler/source/rubygems/remote.rb', line 7

def cooldown
  @cooldown
end

#original_uriObject (readonly)

Returns the value of attribute original_uri.



7
8
9
# File 'lib/bundler/source/rubygems/remote.rb', line 7

def original_uri
  @original_uri
end

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/bundler/source/rubygems/remote.rb', line 7

def uri
  @uri
end

Instance Method Details

#cache_slugString

Returns A slug suitable for use as a cache key for this remote.

Returns:

  • (String)

    A slug suitable for use as a cache key for this remote.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bundler/source/rubygems/remote.rb', line 35

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_cooldownObject

Returns the cooldown days that apply to this remote, resolving the precedence CLI > config > Gemfile per-source. Returns nil if no cooldown applies.



23
24
25
26
27
# File 'lib/bundler/source/rubygems/remote.rb', line 23

def effective_cooldown
  override = Bundler.settings[:cooldown]
  return override if override
  @cooldown
end

#to_sObject



56
57
58
# File 'lib/bundler/source/rubygems/remote.rb', line 56

def to_s
  "rubygems remote at #{anonymized_uri}"
end