Returns a list of pairs of gemspecs and source_uris that match Gem::Dependencydep from both
local (Dir.pwd) and remote (Gem.sources) sources. Gems are sorted with
newer gems preferred over older gems, and local gems preferred over remote
gems.
# File lib/rubygems/dependency_installer.rb, line 85
def find_gems_with_sources(dep)
# Reset the errors
@errors = nil
gems_and_sources = []
if @domain == :both or @domain == :local then
Dir[File.join(Dir.pwd, "#{dep.name}-[0-9]*.gem")].each do |gem_file|
spec = Gem::Format.from_file_by_path(gem_file).spec
gems_and_sources << [spec, gem_file] if spec.name == dep.name
end
end
if @domain == :both or @domain == :remote then
begin
# REFACTOR: all = dep.requirement.needs_all?
requirements = dep.requirement.requirements.map do |req, ver|
req
end
all = !dep.prerelease? &&
# we only need latest if there's one requirement and it is
# guaranteed to match the newest specs
(requirements.length > 1 or
(requirements.first != ">=" and requirements.first != ">"))
found, @errors = Gem::SpecFetcher.fetcher.fetch_with_errors dep, all, true, dep.prerelease?
gems_and_sources.push(*found)
rescue Gem::RemoteFetcher::FetchError => e
if Gem.configuration.really_verbose then
say "Error fetching remote data:\t\t#{e.message}"
say "Falling back to local-only install"
end
@domain = :local
end
end
gems_and_sources.sort_by do |gem, source|
[gem, source =~ /^http:\/\// ? 0 : 1] # local gems win
end
end