Parent

Methods

Class Index [+]

Quicksearch

Gem::Commands::CleanupCommand

Public Class Methods

new() click to toggle source
    # File lib/rubygems/commands/cleanup_command.rb, line 8
 8:   def initialize
 9:     super 'cleanup',
10:           'Clean up old versions of installed gems in the local repository',
11:           :force => false, :test => false, :install_dir => Gem.dir
12: 
13:     add_option('-d', '--dryrun', "") do |value, options|
14:       options[:dryrun] = true
15:     end
16:   end

Public Instance Methods

execute() click to toggle source
     # File lib/rubygems/commands/cleanup_command.rb, line 37
 37:   def execute
 38:     say "Cleaning up installed gems..."
 39:     primary_gems = {}
 40: 
 41:     Gem.source_index.each do |name, spec|
 42:       if primary_gems[spec.name].nil? or
 43:          primary_gems[spec.name].version < spec.version then
 44:         primary_gems[spec.name] = spec
 45:       end
 46:     end
 47: 
 48:     gems_to_cleanup = []
 49: 
 50:     unless options[:args].empty? then
 51:       options[:args].each do |gem_name|
 52:         dep = Gem::Dependency.new gem_name, Gem::Requirement.default
 53:         specs = Gem.source_index.search dep
 54:         specs.each do |spec|
 55:           gems_to_cleanup << spec
 56:         end
 57:       end
 58:     else
 59:       Gem.source_index.each do |name, spec|
 60:         gems_to_cleanup << spec
 61:       end
 62:     end
 63: 
 64:     gems_to_cleanup = gems_to_cleanup.select { |spec|
 65:       primary_gems[spec.name].version != spec.version
 66:     }
 67: 
 68:     deplist = Gem::DependencyList.new
 69:     gems_to_cleanup.uniq.each do |spec| deplist.add spec end
 70: 
 71:     deps = deplist.strongly_connected_components.flatten.reverse
 72: 
 73:     deps.each do |spec|
 74:       if options[:dryrun] then
 75:         say "Dry Run Mode: Would uninstall #{spec.full_name}"
 76:       else
 77:         say "Attempting to uninstall #{spec.full_name}"
 78: 
 79:         options[:args] = [spec.name]
 80: 
 81:         uninstall_options = {
 82:           :executables => false,
 83:           :version => "= #{spec.version}",
 84:         }
 85: 
 86:         if Gem.user_dir == spec.installation_path then
 87:           uninstall_options[:install_dir] = spec.installation_path
 88:         end
 89: 
 90:         uninstaller = Gem::Uninstaller.new spec.name, uninstall_options
 91: 
 92:         begin
 93:           uninstaller.uninstall
 94:         rescue Gem::DependencyRemovalException, Gem::InstallError,
 95:                Gem::GemNotInHomeException => e
 96:           say "Unable to uninstall #{spec.full_name}:"
 97:           say "\t#{e.class}: #{e.message}"
 98:         end
 99:       end
100:     end
101: 
102:     say "Clean Up Complete"
103:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.