Class: Gem::Commands::LocateCommand

Inherits:
QueryCommand
  • Object
show all
Defined in:
lib/commands/locate.rb

Instance Method Summary collapse

Constructor Details

#initializeLocateCommand

Returns a new instance of LocateCommand.



2
3
4
5
6
# File 'lib/commands/locate.rb', line 2

def initialize
  super 'locate', 'Find all gems whose name, summary, or description match STRING'
  
   %w(-p -u).each{|com| remove_option com } 
end

Instance Method Details

#argumentsObject

:nodoc:



8
9
10
# File 'lib/commands/locate.rb', line 8

def arguments # :nodoc:
  "STRING        fragment of gem name,summary, or description to search for"
end

#defaults_strObject

:nodoc:



12
13
14
# File 'lib/commands/locate.rb', line 12

def defaults_str # :nodoc:
  "--local"
end

#executeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/commands/locate.rb', line 20

def execute
  string = get_one_optional_argument
  options[:name] = /#{string}/i    
  exit_code = 0

  name = options[:name]
  prerelease = options[:prerelease]

  if options[:installed] then
    if name.source.empty? then
      alert_error "You must specify a gem name"
      exit_code |= 4
    elsif installed? name, options[:version] then
      say "true"
    else
      say "false"
      exit_code |= 1
    end

    raise Gem::SystemExitException, exit_code
  end

  dep = Gem::Dependency.new name, Gem::Requirement.default

  if local? then
    if prerelease and not both? then
      alert_warning "prereleases are always shown locally"
    end

    if ui.outs.tty? or both? then
      say
      say "*** LOCAL GEMS ***"
      say
    end

    specs = Gem.source_index.locate dep

    spec_tuples = specs.map do |spec|
      [[spec.name, spec.version, spec.original_platform, spec], :local]
    end

    output_query_results spec_tuples
    options[:local] = options[:domain] = nil
  end

  if remote? then
    super
  end
end

#usageObject

:nodoc:



16
17
18
# File 'lib/commands/locate.rb', line 16

def usage # :nodoc:
  "#{program_name} [STRING]"
end