Class: Gem::Commands::StaleCommand

Inherits:
Gem::Command show all
Defined in:
lib/rubygems/commands/stale_command.rb

Constant Summary

Constant Summary

Constants inherited from Gem::Command

Gem::Command::HELP

Instance Attribute Summary

Attributes inherited from Gem::Command

#command, #defaults, #options, #program_name, #summary

Instance Method Summary (collapse)

Methods inherited from Gem::Command

add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #arguments, #begins?, build_args, build_args=, common_options, #defaults_str, #description, extra_args, extra_args=, #get_all_gem_names, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked

Methods included from UserInteraction

#methname

Methods included from DefaultUserInteraction

ui, #ui, #ui=, ui=, use_ui, #use_ui

Constructor Details

- (StaleCommand) initialize

A new instance of StaleCommand



4
5
6
# File 'lib/rubygems/commands/stale_command.rb', line 4

def initialize
  super('stale', 'List gems along with access times')
end

Instance Method Details

- (Object) execute



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubygems/commands/stale_command.rb', line 12

def execute
  gem_to_atime = {}
  Gem.source_index.each do |name, spec|
    Dir["#{spec.full_gem_path}/**/*.*"].each do |file|
      next if File.directory?(file)
      stat = File.stat(file)
      gem_to_atime[name] ||= stat.atime
      gem_to_atime[name] = stat.atime if gem_to_atime[name] < stat.atime
    end
  end

  gem_to_atime.sort_by { |_, atime| atime }.each do |name, atime|
    say "#{name} at #{atime.strftime '%c'}"
  end
end

- (Object) usage

:nodoc:



8
9
10
# File 'lib/rubygems/commands/stale_command.rb', line 8

def usage # :nodoc:
  "#{program_name}"
end