class Bundler::Settings::Mirrors

Class used to build the mirror set and then find a mirror for a given URI

@param prober [Prober object, nil] by default a TCPSocketProbe, this object

will be used to probe the mirror address to validate that the mirror replies.

Public Class Methods

new(prober = nil) click to toggle source
# File bundler/mirror.rb, line 12
def initialize(prober = nil)
  @all = Mirror.new
  @prober = prober || TCPSocketProbe.new
  @mirrors = {}
end

Public Instance Methods

each() { |k, uri.to_s| ... } click to toggle source
# File bundler/mirror.rb, line 30
def each
  @mirrors.each do |k, v|
    yield k, v.uri.to_s
  end
end
for(uri) click to toggle source

Returns a mirror for the given uri.

Depending on the uri having a valid mirror or not, it may be a

mirror that points to the provided uri
# File bundler/mirror.rb, line 22
def for(uri)
  if @all.validate!(@prober).valid?
    @all
  else
    fetch_valid_mirror_for(Settings.normalize_uri(uri))
  end
end
parse(key, value) click to toggle source
# File bundler/mirror.rb, line 36
def parse(key, value)
  config = MirrorConfig.new(key, value)
  mirror = if config.all?
    @all
  else
    @mirrors[config.uri] ||= Mirror.new
  end
  config.update_mirror(mirror)
end

Private Instance Methods

fetch_valid_mirror_for(uri) click to toggle source
# File bundler/mirror.rb, line 48
def fetch_valid_mirror_for(uri)
  downcased = uri.to_s.downcase
  mirror = @mirrors[downcased] || @mirrors[Gem::URI(downcased).host] || Mirror.new(uri)
  mirror.validate!(@prober)
  mirror = Mirror.new(uri) unless mirror.valid?
  mirror
end