install(options, &block)
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 = []
sorted_requests.each do |req|
if req.installed? then
req.spec.spec.build_extensions
if @always_install.none? { |spec| spec == req.spec.spec } then
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)
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]
specs = requests.map do |request|
case request
when Gem::Resolver::ActivationRequest then
request.spec.spec
else
request
end
end
require 'rubygems/dependency_installer'
inst = Gem::DependencyInstaller.new options
inst.installed_gems.replace specs
Gem.done_installing_hooks.each do |hook|
hook.call inst, specs
end unless Gem.done_installing_hooks.empty?
requests
end