def install(spec)
if installed_specs[spec].any? && gem_dir_exists?(spec)
return ["Using #{spec.name} (#{spec.version})", nil]
end
if spec.source_uri
path = Fetcher.download_gem_from_uri(spec, spec.source_uri)
s = Bundler.rubygems.spec_from_gem(path, Bundler.settings["trust-policy"])
spec.__swap__(s)
end
install_message = "Installing #{spec.name} (#{spec.version})"
path = cached_gem(spec)
if Bundler.requires_sudo?
install_path = Bundler.tmp
bin_path = install_path.join("bin")
else
install_path = Bundler.rubygems.gem_dir
bin_path = Bundler.system_bindir
end
installed_spec = nil
Bundler.rubygems.preserve_paths do
installed_spec = Bundler::GemInstaller.new(path,
:install_dir => install_path.to_s,
:bin_dir => bin_path.to_s,
:ignore_dependencies => true,
:wrappers => true,
:env_shebang => true
).install
end
if Bundler.requires_sudo?
Bundler.mkdir_p "#{Bundler.rubygems.gem_dir}/gems"
Bundler.mkdir_p "#{Bundler.rubygems.gem_dir}/specifications"
Bundler.sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Bundler.rubygems.gem_dir}/gems/"
Bundler.sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Bundler.rubygems.gem_dir}/specifications/"
spec.executables.each do |exe|
Bundler.mkdir_p Bundler.system_bindir
Bundler.sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Bundler.system_bindir}"
end
end
installed_spec.loaded_from = "#{Bundler.rubygems.gem_dir}/specifications/#{spec.full_name}.gemspec"
spec.loaded_from = "#{Bundler.rubygems.gem_dir}/specifications/#{spec.full_name}.gemspec"
[install_message, spec.post_install_message]
end