install()
public
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
gems/<gem-version>/... #=> extracted files
specifications/<gem-version>.gemspec
Show source
def install
current_home = Gem.dir
current_path = Gem.paths.path
verify_gem_home(options[:unpack])
Gem.use_paths gem_home, current_path
@security_policy = nil if @force and @security_policy and
not @security_policy.only_signed
unless @force
ensure_required_ruby_version_met
ensure_required_rubygems_version_met
ensure_dependencies_met unless @ignore_dependencies
end
Gem.pre_install_hooks.each do |hook|
result = hook.call self
if result == false then
location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
message = "pre-install hook#{location} failed for #{spec.full_name}"
raise Gem::InstallError, message
end
end
Gem.ensure_gem_subdirectories gem_home
FileUtils.rm_rf(gem_dir) if File.exist? gem_dir
FileUtils.mkdir_p gem_dir
extract_files
build_extensions
Gem.post_build_hooks.each do |hook|
result = hook.call self
if result == false then
FileUtils.rm_rf gem_dir
location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
message = "post-build hook#{location} failed for #{spec.full_name}"
raise Gem::InstallError, message
end
end
generate_bin
write_spec
write_require_paths_file_if_needed if Gem::QUICKLOADER_SUCKAGE
cache_file = spec.cache_file
FileUtils.cp gem, cache_file unless File.exist? cache_file
say spec.post_install_message unless spec.post_install_message.nil?
spec.loaded_from = spec.spec_file
Gem::Specification.add_spec spec unless Gem::Specification.include? spec
Gem.post_install_hooks.each do |hook|
hook.call self
end
return spec
rescue Zlib::GzipFile::Error
raise Gem::InstallError, "gzip error installing #{gem}"
ensure
if current_path
Gem.use_paths current_home, current_path
end
end