install(dep_or_name, version = Gem::Requirement.default)
public
Installs the gem dep_or_name and all its dependencies. Returns an
Array of installed gem specifications.
If the :prerelease option is set and there is a prerelease for
dep_or_name the prerelease version will be installed.
Unless explicitly specified as a prerelease dependency, prerelease gems
that dep_or_name depend on will not be installed.
If c-1.a depends on b-1 and a-1.a and there is a gem b-1.a available then
c-1.a, b-1 and a-1.a will be installed. b-1.a will need to be installed
separately.
Show source
def install dep_or_name, version = Gem::Requirement.default
if String === dep_or_name then
find_spec_by_name_and_version dep_or_name, version, @prerelease
else
dep_or_name.prerelease = @prerelease
@specs_and_sources = [find_gems_with_sources(dep_or_name).last]
end
@installed_gems = []
gather_dependencies
last = @gems_to_install.size - 1
@gems_to_install.each_with_index do |spec, index|
next if Gem::Specification.include?(spec) and index != last
say "Installing gem #{spec.full_name}" if Gem.configuration.really_verbose
_, source_uri = @specs_and_sources.assoc spec
begin
local_gem_path = Gem::RemoteFetcher.fetcher.download spec, source_uri,
@cache_dir
rescue Gem::RemoteFetcher::FetchError
next if @force
raise
end
inst = Gem::Installer.new local_gem_path,
:bin_dir => @bin_dir,
:development => @development,
:env_shebang => @env_shebang,
:force => @force,
:format_executable => @format_executable,
:ignore_dependencies => @ignore_dependencies,
:install_dir => @install_dir,
:security_policy => @security_policy,
:user_install => @user_install,
:wrappers => @wrappers
spec = inst.install
@installed_gems << spec
end
@installed_gems
end