Class: Gem::Commands::CheckCommand

Inherits:
Gem::Command show all
Includes:
VersionOption
Defined in:
lib/rubygems/commands/check_command.rb

Instance Attribute Summary

Attributes inherited from Gem::Command

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

Instance Method Summary collapse

Methods included from VersionOption

#add_platform_option, #add_prerelease_option, #add_version_option, #get_platform_from_requirements

Methods inherited from Gem::Command

add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, #check_deprecated_options, common_options, #deprecate_option, #deprecated?, 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, 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

#initializeCheckCommand

Returns a new instance of CheckCommand.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubygems/commands/check_command.rb', line 10

def initialize
  super 'check', 'Check a gem repository for added or missing files',
        :alien => true, :doctor => false, :dry_run => false, :gems => true

  add_option('-a', '--[no-]alien',
             'Report "unmanaged" or rogue files in the',
             'gem repository') do |value, options|
    options[:alien] = value
  end

  add_option('--[no-]doctor',
             'Clean up uninstalled gems and broken',
             'specifications') do |value, options|
    options[:doctor] = value
  end

  add_option('--[no-]dry-run',
             'Do not remove files, only report what',
             'would be removed') do |value, options|
    options[:dry_run] = value
  end

  add_option('--[no-]gems',
             'Check installed gems for problems') do |value, options|
    options[:gems] = value
  end

  add_version_option 'check'
end

Instance Method Details

#argumentsObject

:nodoc:



74
75
76
# File 'lib/rubygems/commands/check_command.rb', line 74

def arguments # :nodoc:
  'GEMNAME       name of gem to check'
end

#check_gemsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubygems/commands/check_command.rb', line 40

def check_gems
  say 'Checking gems...'
  say
  gems = get_all_gem_names rescue []

  Gem::Validator.new.alien(gems).sort.each do |key, val|
    unless val.empty?
      say "#{key} has #{val.size} problems"
      val.each do |error_entry|
        say "  #{error_entry.path}:"
        say "    #{error_entry.problem}"
      end
    else
      say "#{key} is error-free" if Gem.configuration.verbose
    end
    say
  end
end

#defaults_strObject

:nodoc:



78
79
80
# File 'lib/rubygems/commands/check_command.rb', line 78

def defaults_str # :nodoc:
  '--gems --alien'
end

#descriptionObject

:nodoc:



82
83
84
85
86
87
# File 'lib/rubygems/commands/check_command.rb', line 82

def description # :nodoc:
  <<-EOF
The check command can list and repair problems with installed gems and
specifications and will clean up gems that have been partially uninstalled.
  EOF
end

#doctorObject



59
60
61
62
63
64
65
66
67
# File 'lib/rubygems/commands/check_command.rb', line 59

def doctor
  say 'Checking for files from uninstalled gems...'
  say

  Gem.path.each do |gem_repo|
    doctor = Gem::Doctor.new gem_repo, options[:dry_run]
    doctor.doctor
  end
end

#executeObject



69
70
71
72
# File 'lib/rubygems/commands/check_command.rb', line 69

def execute
  check_gems if options[:gems]
  doctor if options[:doctor]
end

#usageObject

:nodoc:



89
90
91
# File 'lib/rubygems/commands/check_command.rb', line 89

def usage # :nodoc:
  "#{program_name} [OPTIONS] [GEMNAME ...]"
end