123456789_123456789_123456789_123456789_123456789_

Class: Gem::Resolver::BestSet

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ComposedSet, Set
Instance Chain:
self, ComposedSet, Set
Inherits: Gem::Resolver::ComposedSet
Defined in: lib/rubygems/resolver/best_set.rb

Overview

The BestSet chooses the best available method to query a remote index.

It combines IndexSet and APISet

Class Method Summary

ComposedSet - Inherited

.new

Creates a new ComposedSet containing sets.

Set - Inherited

Instance Attribute Summary

ComposedSet - Inherited

#prerelease=

When allow_prerelease is set to true prereleases gems are allowed to match dependencies.

#remote=

Sets the remote network access for all composed sets.

#sets

Set - Inherited

#errors

Errors encountered when resolving gems.

#prerelease

When true, allows matching of requests to prerelease gems.

#remote

Set to true to disable network access for this set.

#remote?

When true, this set is allowed to access the network when looking up specifications or dependencies.

Instance Method Summary

ComposedSet - Inherited

#errors,
#find_all

Finds all specs matching req in all sets.

#prefetch

Prefetches reqs in all sets.

Set - Inherited

#find_all

The find_all method must be implemented.

#prefetch

The #prefetch method may be overridden, but this is not necessary.

Constructor Details

.new(sources = Gem.sources) ⇒ BestSet

Creates a BestSet for the given Gem.sources or Gem.sources if none are specified. Gem.sources must be a ::Gem::SourceList.

[ GitHub ]

  
# File 'lib/rubygems/resolver/best_set.rb', line 13

def initialize(sources = Gem.sources)
  super()

  @sources = sources
end

Instance Method Details

#find_all(req)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/best_set.rb', line 28

def find_all(req) # :nodoc:
  pick_sets if @remote and @sets.empty?

  super
rescue Gem::RemoteFetcher::FetchError => e
  replace_failed_api_set e

  retry
end

#pick_sets

This method is for internal use only.

Picks which sets to use for the configured sources.

[ GitHub ]

  
# File 'lib/rubygems/resolver/best_set.rb', line 22

def pick_sets # :nodoc:
  @sources.each_source do |source|
    @sets << source.dependency_resolver_set
  end
end

#prefetch(reqs)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/best_set.rb', line 38

def prefetch(reqs) # :nodoc:
  pick_sets if @remote and @sets.empty?

  super
end

#pretty_print(q)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/best_set.rb', line 44

def pretty_print(q) # :nodoc:
  q.group 2, '[BestSet', ']' do
    q.breakable
    q.text 'sets:'

    q.breakable
    q.pp @sets
  end
end

#replace_failed_api_set(error)

This method is for internal use only.

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.

[ GitHub ]

  
# File 'lib/rubygems/resolver/best_set.rb', line 61

def replace_failed_api_set(error) # :nodoc:
  uri = error.uri
  uri = URI uri unless URI === uri
  uri.query = nil

  raise error unless api_set = @sets.find { |set|
    Gem::Resolver::APISet === set and set.dep_uri == uri
  }

  index_set = Gem::Resolver::IndexSet.new api_set.source

  @sets.map! do |set|
    next set unless set == api_set
    index_set
  end
end