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('-v', '--verbose', "Spew more words") do |value, options| 25: options[:verbose] = true 26: end 27: 28: add_option('-t', '--test', "Run unit tests for gem") do |value, options| 29: options[:test] = true 30: end 31: 32: add_version_option 'run tests for' 33: end
# File lib/rubygems/commands/check_command.rb, line 35 35: def execute 36: if options[:test] 37: version = options[:version] || Gem::Requirement.default 38: dep = Gem::Dependency.new get_one_gem_name, version 39: gem_spec = Gem::SourceIndex.from_installed_gems.search(dep).first 40: Gem::Validator.new.unit_test(gem_spec) 41: end 42: 43: if options[:alien] 44: say "Performing the 'alien' operation" 45: say 46: gems = get_all_gem_names rescue [] 47: Gem::Validator.new.alien(gems).sort.each do |key, val| 48: unless val.empty? then 49: say "#{key} has #{val.size} problems" 50: val.each do |error_entry| 51: say " #{error_entry.path}:" 52: say " #{error_entry.problem}" 53: end 54: else 55: say "#{key} is error-free" if options[:verbose] 56: end 57: say 58: end 59: end 60: 61: if options[:verify] 62: gem_name = options[:verify] 63: unless gem_name 64: alert_error "Must specify a .gem file with --verify NAME" 65: return 66: end 67: unless File.exist?(gem_name) 68: alert_error "Unknown file: #{gem_name}." 69: return 70: end 71: say "Verifying gem: '#{gem_name}'" 72: begin 73: Gem::Validator.new.verify_gem_file(gem_name) 74: rescue Exception => e 75: alert_error "#{gem_name} is invalid." 76: end 77: end 78: end