2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-11-10 12:51:40 -05:00
|
|
|
##
|
|
|
|
# The BestSet chooses the best available method to query a remote index.
|
|
|
|
#
|
|
|
|
# It combines IndexSet and APISet
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet
|
2013-11-10 12:51:40 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Creates a BestSet for the given +sources+ or Gem::sources if none are
|
|
|
|
# specified. +sources+ must be a Gem::SourceList.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def initialize(sources = Gem.sources)
|
2013-11-10 12:51:40 -05:00
|
|
|
super()
|
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
@sources = sources
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Picks which sets to use for the configured sources.
|
|
|
|
|
|
|
|
def pick_sets # :nodoc:
|
|
|
|
@sources.each_source do |source|
|
2013-11-10 12:51:40 -05:00
|
|
|
@sets << source.dependency_resolver_set
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def find_all(req) # :nodoc:
|
2014-02-03 19:48:31 -05:00
|
|
|
pick_sets if @remote and @sets.empty?
|
|
|
|
|
|
|
|
super
|
2014-09-13 23:30:02 -04:00
|
|
|
rescue Gem::RemoteFetcher::FetchError => e
|
|
|
|
replace_failed_api_set e
|
|
|
|
|
|
|
|
retry
|
2014-02-03 19:48:31 -05:00
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def prefetch(reqs) # :nodoc:
|
2014-02-03 19:48:31 -05:00
|
|
|
pick_sets if @remote and @sets.empty?
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def pretty_print(q) # :nodoc:
|
2013-11-30 18:27:52 -05:00
|
|
|
q.group 2, '[BestSet', ']' do
|
|
|
|
q.breakable
|
|
|
|
q.text 'sets:'
|
|
|
|
|
|
|
|
q.breakable
|
|
|
|
q.pp @sets
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
##
|
|
|
|
# Replaces a failed APISet for the URI in +error+ with an IndexSet.
|
|
|
|
#
|
|
|
|
# If no matching APISet can be found the original +error+ is raised.
|
|
|
|
#
|
|
|
|
# The calling method must retry the exception to repeat the lookup.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def replace_failed_api_set(error) # :nodoc:
|
2014-09-13 23:30:02 -04:00
|
|
|
uri = error.uri
|
|
|
|
uri = URI uri unless URI === uri
|
|
|
|
uri.query = nil
|
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
raise error unless api_set = @sets.find do |set|
|
2014-09-13 23:30:02 -04:00
|
|
|
Gem::Resolver::APISet === set and set.dep_uri == uri
|
2019-02-14 07:59:03 -05:00
|
|
|
end
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
index_set = Gem::Resolver::IndexSet.new api_set.source
|
|
|
|
|
|
|
|
@sets.map! do |set|
|
|
|
|
next set unless set == api_set
|
|
|
|
index_set
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|