Class Gem::Commands::CheckCommand
In: lib/rubygems/commands/check_command.rb
Parent: Gem::Command

Methods

execute   new  

Included Modules

Gem::VersionOption

Public Class methods

[Source]

    # File lib/rubygems/commands/check_command.rb, line 9
 9:   def initialize
10:     super 'check', 'Check installed gems',
11:           :verify => false, :alien => false
12: 
13:     add_option(      '--verify FILE',
14:                'Verify gem file against its internal',
15:                'checksum') do |value, options|
16:       options[:verify] = value
17:     end
18: 
19:     add_option('-a', '--alien', "Report 'unmanaged' or rogue files in the",
20:                "gem repository") do |value, options|
21:       options[:alien] = true
22:     end
23: 
24:     add_option('-t', '--test', "Run unit tests for gem") do |value, options|
25:       options[:test] = true
26:     end
27: 
28:     add_version_option 'run tests for'
29:   end

Public Instance methods

[Source]

    # File lib/rubygems/commands/check_command.rb, line 31
31:   def execute
32:     if options[:test]
33:       version = options[:version] || Gem::Requirement.default
34:       dep = Gem::Dependency.new get_one_gem_name, version
35:       gem_spec = Gem::SourceIndex.from_installed_gems.search(dep).first
36:       Gem::Validator.new.unit_test(gem_spec)
37:     end
38: 
39:     if options[:alien]
40:       say "Performing the 'alien' operation"
41:       Gem::Validator.new.alien.each do |key, val|
42:         if(val.size > 0)
43:           say "#{key} has #{val.size} problems"
44:           val.each do |error_entry|
45:             say "\t#{error_entry.path}:"
46:             say "\t#{error_entry.problem}"
47:             say
48:           end
49:         else  
50:           say "#{key} is error-free"
51:         end
52:         say
53:       end
54:     end
55: 
56:     if options[:verify]
57:       gem_name = options[:verify]
58:       unless gem_name
59:         alert_error "Must specify a .gem file with --verify NAME"
60:         return
61:       end
62:       unless File.exist?(gem_name)
63:         alert_error "Unknown file: #{gem_name}."
64:         return
65:       end
66:       say "Verifying gem: '#{gem_name}'"
67:       begin
68:         Gem::Validator.new.verify_gem_file(gem_name)
69:       rescue Exception => e
70:         alert_error "#{gem_name} is invalid."
71:       end
72:     end
73:   end

[Validate]