/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/commands/stale_command.rb

http://github.com/agross/netopenspace · Ruby · 27 lines · 23 code · 4 blank · 0 comment · 2 complexity · 90314b94478b94d5183dbf3e1e8ad3e1 MD5 · raw file

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