# File lib/rubygems/commands/cleanup_command.rb, line 7 7: def initialize 8: super 'cleanup', 9: 'Clean up old versions of installed gems in the local repository', 10: :force => false, :install_dir => Gem.dir 11: 12: add_option('-d', '--dryrun', "") do |value, options| 13: options[:dryrun] = true 14: end 15: end
# File lib/rubygems/commands/cleanup_command.rb, line 36 36: def execute 37: say "Cleaning up installed gems..." 38: primary_gems = {} 39: 40: Gem::Specification.each do |spec| 41: if primary_gems[spec.name].nil? or 42: primary_gems[spec.name].version < spec.version then 43: primary_gems[spec.name] = spec 44: end 45: end 46: 47: gems_to_cleanup = unless options[:args].empty? then 48: options[:args].map do |gem_name| 49: Gem::Specification.find_all_by_name gem_name 50: end.flatten 51: else 52: Gem::Specification.to_a 53: end 54: 55: gems_to_cleanup = gems_to_cleanup.select { |spec| 56: primary_gems[spec.name].version != spec.version 57: } 58: 59: deplist = Gem::DependencyList.new 60: gems_to_cleanup.uniq.each do |spec| deplist.add spec end 61: 62: deps = deplist.strongly_connected_components.flatten.reverse 63: 64: original_path = Gem.path 65: 66: deps.each do |spec| 67: if options[:dryrun] then 68: say "Dry Run Mode: Would uninstall #{spec.full_name}" 69: else 70: say "Attempting to uninstall #{spec.full_name}" 71: 72: options[:args] = [spec.name] 73: 74: uninstall_options = { 75: :executables => false, 76: :version => "= #{spec.version}", 77: } 78: 79: uninstall_options[:user_install] = Gem.user_dir == spec.base_dir 80: 81: uninstaller = Gem::Uninstaller.new spec.name, uninstall_options 82: 83: begin 84: uninstaller.uninstall 85: rescue Gem::DependencyRemovalException, Gem::InstallError, 86: Gem::GemNotInHomeException, Gem::FilePermissionError => e 87: say "Unable to uninstall #{spec.full_name}:" 88: say "\t#{e.class}: #{e.message}" 89: end 90: end 91: 92: # Restore path Gem::Uninstaller may have change 93: Gem.use_paths(*original_path) 94: end 95: 96: say "Clean Up Complete" 97: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.