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, 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:     dep = Gem::Dependency.new name, Gem::Requirement.default
 73: 
 74:     if local? then
 75:       if ui.outs.tty? or both? then
 76:         say
 77:         say "*** LOCAL GEMS ***"
 78:         say
 79:       end
 80: 
 81:       specs = Gem.source_index.search dep
 82: 
 83:       spec_tuples = specs.map do |spec|
 84:         [[spec.name, spec.version, spec.original_platform, spec], :local]
 85:       end
 86: 
 87:       output_query_results spec_tuples
 88:     end
 89: 
 90:     if remote? then
 91:       if ui.outs.tty? or both? then
 92:         say
 93:         say "*** REMOTE GEMS ***"
 94:         say
 95:       end
 96: 
 97:       all = options[:all]
 98: 
 99:       begin
100:         fetcher = Gem::SpecFetcher.fetcher
101:         spec_tuples = fetcher.find_matching dep, all, false
102:       rescue Gem::RemoteFetcher::FetchError => e
103:         raise unless fetcher.warn_legacy e do
104:           require 'rubygems/source_info_cache'
105: 
106:           dep.name = '' if dep.name == //
107: 
108:           specs = Gem::SourceInfoCache.search_with_source dep, false, all
109: 
110:           spec_tuples = specs.map do |spec, source_uri|
111:             [[spec.name, spec.version, spec.original_platform, spec],
112:              source_uri]
113:           end
114:         end
115:       end
116: 
117:       output_query_results spec_tuples
118:     end
119:   end

[Validate]