28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/rubygems/commands/remove_stale_command.rb', line 28
def execute
days = options[:days] || 40
border_time = Time.now - days * (24 * 60 * 60)
stale_gems = Gem::Specification.select do |spec|
stale_gem?(spec, border_time)
end
to_uninstall = stale_gems.select do |spec|
spec.dependent_gems.all? do |dependent, depency, satlist|
stale_gems.include?(dependent) || (satlist - stale_gems).length > 0
end
end
if to_uninstall.empty?
puts 'No stale gems found.'
else
puts 'Stale gems:'
to_uninstall.group_by(&:name).sort.each do |name, specs|
all_versions = Gem::Specification.find_all_by_name(name).map(&:version)
versions_to_uninstall = specs.map(&:version).sort
versions_to_leave = all_versions - versions_to_uninstall
line = " #{name}: #{versions_to_uninstall.join(', ')}"
unless versions_to_leave.empty?
line << " (leaving versions: #{versions_to_leave.join(', ')})"
end
puts line
end
if options[:yes] || ask_yes_no('Remove gems?')
to_uninstall.each do |spec|
say "Attempting to uninstall #{spec.full_name}"
begin
Gem::Uninstaller.new(spec.name, {
:version => "= #{spec.version}",
:executables => true,
:ignore => true
}).uninstall
rescue Gem::DependencyRemovalException, Gem::InstallError, Gem::GemNotInHomeException => e
say "Unable to uninstall #{spec.full_name}:"
say " #{e.class}: #{e.message}"
end
end
end
end
end
|