Class: Gem::Commands::CtagsCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/ctags_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCtagsCommand

Returns a new instance of CtagsCommand.



4
5
6
# File 'lib/rubygems/commands/ctags_command.rb', line 4

def initialize
  super 'ctags', 'Generate ctags for gems'
end

Class Method Details

.index(spec) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rubygems/commands/ctags_command.rb', line 20

def self.index(spec)
  return unless File.directory?(spec.full_gem_path)

  Dir.chdir(spec.full_gem_path) do

    if !(File.file?('tags') && File.read('tags', 1) == '!') && !File.directory?('tags')
      yield "Generating ctags for #{spec.full_name}" if block_given?
      paths = spec.require_paths.select { |p| File.directory?(p) }
      system('ctags', '-R', '--languages=ruby', *paths)
    end

    target = 'lib/bundler/cli.rb'
    if File.writable?(target) && !File.read(target).include?('load_plugins')
      yield "Injecting gem-ctags into #{spec.full_name}" if block_given?
      File.open(target, 'a') do |f|
        f.write "\nGem.load_plugins rescue nil\n"
      end
    end

  end
rescue => e
  raise unless block_given?
  yield "Failed processing ctags for #{spec.full_name}:\n  (#{e.class}) #{e}"
end

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rubygems/commands/ctags_command.rb', line 8

def execute
  if Gem::Specification.respond_to?(:each)
    Gem::Specification
  else
    Gem.source_index.gems.values
  end.each do |spec|
    self.class.index(spec) do |message|
      say message
    end
  end
end