Installs the gem and returns a loaded Gem::Specification for the installed
gem.
The gem will be installed with the following structure:
@gem_home/cache/<gem-version>.gem#=> a cached copy of the installed gemgems/<gem-version>/... #=> extracted files
specifications/<gem-version>.gemspec#=> the Gem::Specification
# File lib/rubygems/installer.rb, line 278
def install
pre_install_checks
FileUtils.rm_f File.join gem_home, 'specifications', spec.spec_name
run_pre_install_hooks
# Set loaded_from to ensure extension_dir is correct
if @options[:install_as_default] then
spec.loaded_from = default_spec_file
else
spec.loaded_from = spec_file
end
# Completely remove any previous gem files
FileUtils.rm_rf gem_dir
FileUtils.rm_rf spec.extension_dir
FileUtils.mkdir_p gem_dir
if @options[:install_as_default] then
extract_bin
write_default_spec
else
extract_files
build_extensions
write_build_info_file
run_post_build_hooks
generate_bin
write_spec
write_cache_file
end
say spec.post_install_message if options[:post_install_message] && !spec.post_install_message.nil?
Gem::Installer.install_lock.synchronize { Gem::Specification.reset }
run_post_install_hooks
spec
# TODO This rescue is in the wrong place. What is raising this exception?
# move this rescue to around the code that actually might raise it.
rescue Zlib::GzipFile::Error
raise Gem::InstallError, "gzip error installing #{gem}"
end