Class: Gem::Commands::StaleCommand

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

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=, #check_deprecated_options, common_options, #defaults_str, #deprecate_option, extra_args, extra_args=, #get_all_gem_names, #get_all_gem_names_and_versions, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #invoke_with_build_args, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked

Methods included from UserInteraction

#alert, #alert_error, #alert_warning, #ask, #ask_for_password, #ask_yes_no, #choose_from_list, #say, #terminate_interaction, #verbose

Methods included from DefaultUserInteraction

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

Methods included from Text

#clean_text, #format_text, #levenshtein_distance, #min3, #truncate_text

Constructor Details

#initializeStaleCommand

Returns a new instance of StaleCommand.



6
7
8
# File 'lib/rubygems/commands/stale_command.rb', line 6

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

Instance Method Details

#descriptionObject

:nodoc:



10
11
12
13
14
15
16
17
18
# File 'lib/rubygems/commands/stale_command.rb', line 10

def description # :nodoc:
  <<-EOF
The stale command lists the latest access time for all the files in your
installed gems.

You can use this command to discover gems and gem versions you are no
longer using.
  EOF
end

#executeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rubygems/commands/stale_command.rb', line 24

def execute
  gem_to_atime = {}
  Gem::Specification.each do |spec|
    name = spec.full_name
    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

#usageObject

:nodoc:



20
21
22
# File 'lib/rubygems/commands/stale_command.rb', line 20

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