diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2016-01-04 20:30:32 -0600 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-01-25 10:49:51 -0600 |
commit | aef6682fcfd3bf7eb6f75a2c2f5dbdaca7e44743 (patch) | |
tree | 136ecda1129cd79c99192dab3d62a8d1535d05f0 /lib | |
parent | c2432bc4d967ab498c9b2eb4f83479668b4b197e (diff) | |
download | bundler-aef6682fcfd3bf7eb6f75a2c2f5dbdaca7e44743.tar.gz |
Refactor cache slug logic into the Remote
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/fetcher/compact_index.rb | 7 | ||||
-rw-r--r-- | lib/bundler/source/rubygems/remote.rb | 18 |
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb index d4be8931b4..d58c165985 100644 --- a/lib/bundler/fetcher/compact_index.rb +++ b/lib/bundler/fetcher/compact_index.rb @@ -74,12 +74,7 @@ module Bundler end def cache_path - cache_uri = remote.cache_uri - uri_parts = [cache_uri.host, cache_uri.port, cache_uri.path].compact.join(".") - uri_digest = Digest::MD5.hexdigest(uri_parts) - - cache_path = [cache_uri.host, cache_uri.port, uri_digest[0..5]].compact.join(".") - Bundler.user_cache.join("compact_index", cache_path) + Bundler.user_cache.join("compact_index", remote.cache_slug) end end end diff --git a/lib/bundler/source/rubygems/remote.rb b/lib/bundler/source/rubygems/remote.rb index 376ce3ee7d..4cd8ea23b8 100644 --- a/lib/bundler/source/rubygems/remote.rb +++ b/lib/bundler/source/rubygems/remote.rb @@ -2,7 +2,7 @@ module Bundler class Source class Rubygems class Remote - attr_reader :uri, :anonymized_uri, :original_uri, :cache_uri + attr_reader :uri, :anonymized_uri, :original_uri def initialize(uri) orig_uri = uri @@ -12,7 +12,21 @@ module Bundler @uri = apply_auth(uri, fallback_auth).freeze @anonymized_uri = remove_auth(@uri).freeze - @cache_uri = remove_auth(orig_uri.dup).freeze + end + + # @return [String] A slug suitable for use as a cache key for this + # remote. + # + def cache_slug + @cache_slug ||= begin + cache_uri = original_uri || uri + + uri_parts = [cache_uri.host, cache_uri.user, cache_uri.port, cache_uri.path] + uri_digest = Digest::MD5.hexdigest(uri_parts.compact.join(".")) + + uri_parts[-1] = uri_digest + uri_parts.compact.join(".") + end end private |