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