Class: Gem::QueryCommand

Inherits:
Command show all
Includes:
LocalRemoteOptions
Defined in:
lib/rubygems/gem_commands.rb

Direct Known Subclasses

ListCommand, SearchCommand

Instance Attribute Summary

Attributes inherited from Command

#command, #defaults, #options, #program_name, #summary

Instance Method Summary collapse

Methods included from LocalRemoteOptions

#add_local_remote_options, #local?, #remote?

Methods inherited from Command

add_common_option, #add_option, add_specific_extra_args, #arguments, common_options, extra_args, extra_args=, #handles?, #invoke, #merge_options, #remove_option, #show_help, specific_extra_args, specific_extra_args_hash, #usage, #when_invoked

Methods included from DefaultUserInteraction

#ui, ui, #ui=, ui=, #use_ui, use_ui

Constructor Details

#initialize(name = 'query', summary = 'Query gem information in local or remote repositories') ⇒ QueryCommand

Returns a new instance of QueryCommand.



779
780
781
782
783
784
785
786
787
788
789
790
791
# File 'lib/rubygems/gem_commands.rb', line 779

def initialize(name='query', summary='Query gem information in local or remote repositories')
  super(name,
    summary,
    {:name=>/.*/, :domain=>:local, :details=>false}
    )
  add_option('-n', '--name-matches REGEXP', 'Name of gem(s) to query on matches the provided REGEXP') do |value, options|
    options[:name] = /#{value}/i
  end
  add_option('-d', '--[no-]details', 'Display detailed information of gem(s)') do |value, options|
    options[:details] = value
  end
  add_local_remote_options
end

Instance Method Details

#defaults_strObject



793
794
795
# File 'lib/rubygems/gem_commands.rb', line 793

def defaults_str
  "--local --name-matches '.*' --no-details"
end

#executeObject



797
798
799
800
801
802
803
804
805
806
807
808
# File 'lib/rubygems/gem_commands.rb', line 797

def execute
  if local?
    say
    say "*** LOCAL GEMS ***"
    output_query_results(Gem::cache.search(options[:name]))
  end
  if remote?
    say
    say "*** REMOTE GEMS ***"
    output_query_results(Gem::SourceInfoCache.search(options[:name]))
  end
end