Class Gem::Commands::QueryCommand
In: lib/rubygems/commands/query_command.rb
Parent: Gem::Command

Methods

execute   new  

Included Modules

Gem::LocalRemoteOptions Gem::VersionOption

Public Class methods

[Source]

    # File lib/rubygems/commands/query_command.rb, line 11
11:   def initialize(name = 'query',
12:                  summary = 'Query gem information in local or remote repositories')
13:     super name, summary,
14:          :name => //, :domain => :local, :details => false, :versions => true,
15:          :installed => false, :version => Gem::Requirement.default
16: 
17:     add_option('-i', '--[no-]installed',
18:                'Check for installed gem') do |value, options|
19:       options[:installed] = value
20:     end
21: 
22:     add_version_option
23: 
24:     add_option('-n', '--name-matches REGEXP',
25:                'Name of gem(s) to query on matches the',
26:                'provided REGEXP') do |value, options|
27:       options[:name] = /#{value}/i
28:     end
29: 
30:     add_option('-d', '--[no-]details',
31:                'Display detailed information of gem(s)') do |value, options|
32:       options[:details] = value
33:     end
34: 
35:     add_option(      '--[no-]versions',
36:                'Display only gem names') do |value, options|
37:       options[:versions] = value
38:       options[:details] = false unless value
39:     end
40: 
41:     add_option('-a', '--all',
42:                'Display all gem versions') do |value, options|
43:       options[:all] = value
44:     end
45: 
46:     add_local_remote_options
47:   end

Public Instance methods

[Source]

     # File lib/rubygems/commands/query_command.rb, line 53
 53:   def execute
 54:     exit_code = 0
 55: 
 56:     name = options[:name]
 57: 
 58:     if options[:installed] then
 59:       if name.source.empty? then
 60:         alert_error "You must specify a gem name"
 61:         exit_code |= 4
 62:       elsif installed? name.source, options[:version] then
 63:         say "true"
 64:       else
 65:         say "false"
 66:         exit_code |= 1
 67:       end
 68: 
 69:       raise Gem::SystemExitException, exit_code
 70:     end
 71: 
 72:     if local? then
 73:       say
 74:       say "*** LOCAL GEMS ***"
 75:       say
 76: 
 77:       specs = Gem.source_index.search name
 78: 
 79:       spec_tuples = specs.map do |spec|
 80:         [[spec.name, spec.version, spec.original_platform, spec], :local]
 81:       end
 82: 
 83:       output_query_results spec_tuples
 84:     end
 85: 
 86:     if remote? then
 87:       say
 88:       say "*** REMOTE GEMS ***"
 89:       say
 90: 
 91:       all = options[:all]
 92: 
 93:       dep = Gem::Dependency.new name, Gem::Requirement.default
 94:       begin
 95:         fetcher = Gem::SpecFetcher.fetcher
 96:         spec_tuples = fetcher.find_matching dep, all, false
 97:       rescue Gem::RemoteFetcher::FetchError => e
 98:         raise unless fetcher.warn_legacy e do
 99:           require 'rubygems/source_info_cache'
100: 
101:           dep.name = '' if dep.name == //
102: 
103:           specs = Gem::SourceInfoCache.search_with_source dep, false, all
104: 
105:           spec_tuples = specs.map do |spec, source_uri|
106:             [[spec.name, spec.version, spec.original_platform, spec],
107:              source_uri]
108:           end
109:         end
110:       end
111: 
112:       output_query_results spec_tuples
113:     end
114:   end

[Validate]