Class Gem::Commands::InstallCommand
In: lib/rubygems/commands/install_command.rb
Parent: Gem::Command

Methods

execute   new  

Included Modules

Gem::VersionOption Gem::LocalRemoteOptions Gem::InstallUpdateOptions

Public Class methods

[Source]

    # File lib/rubygems/commands/install_command.rb, line 15
15:   def initialize
16:     defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({
17:       :generate_rdoc => true,
18:       :generate_ri   => true,
19:       :format_executable => false,
20:       :test => false,
21:       :version => Gem::Requirement.default,
22:     })
23: 
24:     super 'install', 'Install a gem into the local repository', defaults
25: 
26:     add_install_update_options
27:     add_local_remote_options
28:     add_platform_option
29:     add_version_option
30:   end

Public Instance methods

[Source]

     # File lib/rubygems/commands/install_command.rb, line 59
 59:   def execute
 60:     if options[:include_dependencies] then
 61:       alert "`gem install -y` is now default and will be removed"
 62:       alert "use --ignore-dependencies to install only the gems you list"
 63:     end
 64: 
 65:     installed_gems = []
 66: 
 67:     ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
 68: 
 69:     install_options = {
 70:       :env_shebang => options[:env_shebang],
 71:       :domain => options[:domain],
 72:       :force => options[:force],
 73:       :format_executable => options[:format_executable],
 74:       :ignore_dependencies => options[:ignore_dependencies],
 75:       :install_dir => options[:install_dir],
 76:       :security_policy => options[:security_policy],
 77:       :wrappers => options[:wrappers],
 78:       :bin_dir => options[:bin_dir],
 79:       :development => options[:development],
 80:     }
 81: 
 82:     exit_code = 0
 83: 
 84:     get_all_gem_names.each do |gem_name|
 85:       begin
 86:         inst = Gem::DependencyInstaller.new install_options
 87:         inst.install gem_name, options[:version]
 88: 
 89:         inst.installed_gems.each do |spec|
 90:           say "Successfully installed #{spec.full_name}"
 91:         end
 92: 
 93:         installed_gems.push(*inst.installed_gems)
 94:       rescue Gem::InstallError => e
 95:         alert_error "Error installing #{gem_name}:\n\t#{e.message}"
 96:         exit_code |= 1
 97:       rescue Gem::GemNotFoundException => e
 98:         alert_error e.message
 99:         exit_code |= 2
100: #      rescue => e
101: #        # TODO: Fix this handle to allow the error to propagate to
102: #        # the top level handler.  Examine the other errors as
103: #        # well.  This implementation here looks suspicious to me --
104: #        # JimWeirich (4/Jan/05)
105: #        alert_error "Error installing gem #{gem_name}: #{e.message}"
106: #        return
107:       end
108:     end
109: 
110:     unless installed_gems.empty? then
111:       gems = installed_gems.length == 1 ? 'gem' : 'gems'
112:       say "#{installed_gems.length} #{gems} installed"
113:     end
114: 
115:     # NOTE: *All* of the RI documents must be generated first.
116:     # For some reason, RI docs cannot be generated after any RDoc
117:     # documents are generated.
118: 
119:     if options[:generate_ri] then
120:       installed_gems.each do |gem|
121:         Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
122:       end
123: 
124:       Gem::DocManager.update_ri_cache
125:     end
126: 
127:     if options[:generate_rdoc] then
128:       installed_gems.each do |gem|
129:         Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
130:       end
131:     end
132: 
133:     if options[:test] then
134:       installed_gems.each do |spec|
135:         gem_spec = Gem::SourceIndex.from_installed_gems.search(spec.name, spec.version.version).first
136:         result = Gem::Validator.new.unit_test(gem_spec)
137:         if result and not result.passed?
138:           unless ask_yes_no("...keep Gem?", true) then
139:             Gem::Uninstaller.new(spec.name, :version => spec.version.version).uninstall
140:           end
141:         end
142:       end
143:     end
144: 
145:     raise Gem::SystemExitException, exit_code
146:   end

[Validate]