1require 'rubygems/command'
2
3class Gem::Commands::StaleCommand < Gem::Command
4  def initialize
5    super('stale', 'List gems along with access times')
6  end
7
8  def usage # :nodoc:
9    "#{program_name}"
10  end
11
12  def execute
13    gem_to_atime = {}
14    Gem::Specification.each do |spec|
15      name = spec.full_name
16      Dir["#{spec.full_gem_path}/**/*.*"].each do |file|
17        next if File.directory?(file)
18        stat = File.stat(file)
19        gem_to_atime[name] ||= stat.atime
20        gem_to_atime[name] = stat.atime if gem_to_atime[name] < stat.atime
21      end
22    end
23
24    gem_to_atime.sort_by { |_, atime| atime }.each do |name, atime|
25      say "#{name} at #{atime.strftime '%c'}"
26    end
27  end
28end
29