install(options)
public
Installs gems for this RequestSet using the Gem::Installer options.
If a block is given an activation request and
installer are yielded. The installer will be nil
if a gem matching the request was
already installed.
Show source
def install(options, &block)
if dir = options[:install_dir]
requests = install_into dir, false, options, &block
return requests
end
@prerelease = options[:prerelease]
requests = []
download_queue = Queue.new
sorted_requests.each do |req|
download_queue << req
end
threads = Gem.configuration.concurrent_downloads.times.map do
download_queue << :stop
Thread.new do
while req = download_queue.pop
break if req == :stop
req.spec.download options unless req.installed?
end
end
end
threads.each(&:value)
sorted_requests.each do |req|
if req.installed?
req.spec.spec.build_extensions
if @always_install.none? { |spec| spec == req.spec.spec }
yield req, nil if block_given?
next
end
end
spec =
begin
req.spec.install options do |installer|
yield req, installer if block_given?
end
rescue Gem::RuntimeRequirementNotMetError => e
recent_match = req.spec.set.find_all(req.request).sort_by(&:version).reverse_each.find do |s|
s = s.spec
s.required_ruby_version.satisfied_by?(Gem.ruby_version) &&
s.required_rubygems_version.satisfied_by?(Gem.rubygems_version) &&
Gem::Platform.installable?(s)
end
if recent_match
suggestion = "The last version of #{req.request} to support your Ruby & RubyGems was #{recent_match.version}. Try installing it with `gem install #{recent_match.name} -v #{recent_match.version}`"
suggestion += " and then running the current command again" unless @always_install.include?(req.spec.spec)
else
suggestion = "There are no versions of #{req.request} compatible with your Ruby & RubyGems"
suggestion += ". Maybe try installing an older version of the gem you're looking for?" unless @always_install.include?(req.spec.spec)
end
e.suggestion = suggestion
raise
end
requests << spec
end
return requests if options[:gemdeps]
install_hooks requests, options
requests
end