Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • rubygems/commands/install_command.rb

Class/Module Index [+]

Quicksearch

Gem::Commands::InstallCommand

Gem installer command line tool

See `gem help install`

Public Class Methods

new() click to toggle source
 
               # File rubygems/commands/install_command.rb, line 20
def initialize
  defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({
    :generate_rdoc     => true,
    :generate_ri       => true,
    :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)"
end
            

Public Instance Methods

execute() click to toggle source
 
               # File rubygems/commands/install_command.rb, line 103
def execute
  if options[:include_dependencies] then
    alert "`gem install -y` is now default and will be removed"
    alert "use --ignore-dependencies to install only the gems you list"
  end

  installed_gems = []

  ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'

  exit_code = 0

  get_all_gem_names.each do |gem_name|
    begin
      next if options[:conservative] and
        not Gem::Dependency.new(gem_name, options[:version]).matching_specs.empty?

      inst = Gem::DependencyInstaller.new options
      inst.install gem_name, options[:version]

      inst.installed_gems.each do |spec|
        say "Successfully installed #{spec.full_name}"
      end

      installed_gems.push(*inst.installed_gems)
    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_gems.empty? then
    gems = installed_gems.length == 1 ? 'gem' : 'gems'
    say "#{installed_gems.length} #{gems} installed"

    # NOTE: *All* of the RI documents must be generated first.  For some
    # reason, RI docs cannot be generated after any RDoc documents are
    # generated.

    if options[:generate_ri] then
      installed_gems.each do |gem|
        Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
      end

      Gem::DocManager.update_ri_cache
    end

    if options[:generate_rdoc] then
      installed_gems.each do |gem|
        Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
      end
    end
  end

  raise Gem::SystemExitException, exit_code
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.