method
install
v2_6_3 -
Show latest stable
- Class:
Gem::RequestSet
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.
# File lib/rubygems/request_set.rb, line 146
def install(options, &block) # :yields: request, installer
if dir = options[:install_dir]
requests = install_into dir, false, options, &block
return requests
end
@prerelease = options[:prerelease]
requests = []
download_queue = Queue.new
# Create a thread-safe list of gems to download
sorted_requests.each do |req|
download_queue << req
end
# Create N threads in a pool, have them download all the gems
threads = Gem.configuration.concurrent_downloads.times.map do
# When a thread pops this item, it knows to stop running. The symbol
# is queued here so that there will be one symbol per thread.
download_queue << :stop
Thread.new do
# The pop method will block waiting for items, so the only way
# to stop a thread from running is to provide a final item that
# means the thread should stop.
while req = download_queue.pop
break if req == :stop
req.spec.download options unless req.installed?
end
end
end
# Wait for all the downloads to finish before continuing
threads.each(&:value)
# Install requested gems after they have been downloaded
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 Related methods
- Instance methods
- gem
- import
- install
- install_from_gemdeps
- install_hooks
- install_into
- load_gemdeps
- pretty_print
- resolve
- resolve_current
- sorted_requests
- specs
- specs_in
- tsort_each_child
- tsort_each_node
- Class methods
- new