class Gem::Commands::InstallCommand
Gem installer command line tool
See `gem help install`
Public Class Methods
new()
click to toggle source
Calls superclass method
Gem::Command.new
# File lib/rubygems/commands/install_command.rb, line 23 def initialize defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({ :format_executable => false, :version => Gem::Requirement.default, }) super 'install', 'Install a gem into the local repository', defaults add_install_update_options add_local_remote_options add_platform_option add_version_option add_prerelease_option "to be installed. (Only for listed gems)" add_option(:"Install/Update", '-g', '--file FILE', 'Read from a gem dependencies API file and', 'install the listed gems') do |v,o| o[:gemdeps] = v end @installed_specs = nil end
Public Instance Methods
execute()
click to toggle source
# File lib/rubygems/commands/install_command.rb, line 134 def execute if gf = options[:gemdeps] then install_from_gemdeps gf return end @installed_specs = [] ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9' if options[:install_dir] and options[:user_install] alert_error "Use --install-dir or --user-install but not both" terminate_interaction 1 end exit_code = 0 if options[:version] != Gem::Requirement.default && get_all_gem_names.size > 1 then alert_error "Can't use --version w/ multiple gems. Use name:ver instead." terminate_interaction 1 end get_all_gem_names_and_versions.each do |gem_name, gem_version| gem_version ||= options[:version] begin next if options[:conservative] and not Gem::Dependency.new(gem_name, gem_version).matching_specs.empty? inst = Gem::DependencyInstaller.new options inst.install gem_name, Gem::Requirement.create(gem_version) @installed_specs.push(*inst.installed_gems) next unless errs = inst.errors errs.each do |x| next unless Gem::SourceFetchProblem === x msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}" alert_warning msg end rescue Gem::InstallError => e alert_error "Error installing #{gem_name}:\n\t#{e.message}" exit_code |= 1 rescue Gem::GemNotFoundException => e show_lookup_failure e.name, e.version, e.errors, options[:domain] exit_code |= 2 end end unless @installed_specs.empty? then gems = @installed_specs.length == 1 ? 'gem' : 'gems' say "#{@installed_specs.length} #{gems} installed" end raise Gem::SystemExitException, exit_code end
install_from_gemdeps(gf)
click to toggle source
# File lib/rubygems/commands/install_command.rb, line 112 def install_from_gemdeps(gf) require 'rubygems/request_set' rs = Gem::RequestSet.new rs.load_gemdeps gf rs.resolve specs = rs.install options do |req, inst| s = req.full_spec if inst say "Installing #{s.name} (#{s.version})" else say "Using #{s.name} (#{s.version})" end end @installed_specs = specs raise Gem::SystemExitException, 0 end