PageRenderTime 42ms CodeModel.GetById 36ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/commands/check_command.rb

http://github.com/agross/netopenspace
Ruby | 65 lines | 56 code | 9 blank | 0 comment | 2 complexity | b3e5e6766b67ce5c82408a50501b4aba MD5 | raw file
 1require 'rubygems/command'
 2require 'rubygems/version_option'
 3require 'rubygems/validator'
 4
 5class Gem::Commands::CheckCommand < Gem::Command
 6
 7  include Gem::VersionOption
 8
 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_version_option 'check'
25  end
26
27  def execute
28    if options[:alien]
29      say "Performing the 'alien' operation"
30      say
31      gems = get_all_gem_names rescue []
32      Gem::Validator.new.alien(gems).sort.each do |key, val|
33        unless val.empty? then
34          say "#{key} has #{val.size} problems"
35          val.each do |error_entry|
36            say "  #{error_entry.path}:"
37            say "    #{error_entry.problem}"
38          end
39        else
40          say "#{key} is error-free" if Gem.configuration.verbose
41        end
42        say
43      end
44    end
45
46    if options[:verify]
47      gem_name = options[:verify]
48      unless gem_name
49        alert_error "Must specify a .gem file with --verify NAME"
50        return
51      end
52      unless File.exist?(gem_name)
53        alert_error "Unknown file: #{gem_name}."
54        return
55      end
56      say "Verifying gem: '#{gem_name}'"
57      begin
58        Gem::Validator.new.verify_gem_file(gem_name)
59      rescue Exception
60        alert_error "#{gem_name} is invalid."
61      end
62    end
63  end
64
65end