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.



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

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

Class Method Details

.can_write?(path) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/rubygems/commands/ctags_command.rb', line 31

def self.can_write?(path)
  path.dirname.directory? && !path.directory? &&
    !(path.file? && path.read(1) == '!')
end

.index(spec, ui = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rubygems/commands/ctags_command.rb', line 36

def self.index(spec, ui = nil)
  gem_path = Pathname.new(spec.full_gem_path)

  tag_file = gem_path.join('tags')
  paths = spec.require_paths.map { |p| gem_path.join(p) }
  if paths.any? && can_write?(tag_file)
    ui.say "Generating ctags for #{spec.full_name}" if ui
    invoke('Ruby', tag_file, *paths)
  end

  target = gem_path.join('lib/bundler/cli.rb')
  if target.writable? && !target.read.include?('load_plugins')
    ui.say "Injecting gem-ctags into #{spec.full_name}" if ui
    target.open('a') do |f|
      f.write "\nGem.load_plugins rescue nil\n"
    end
  end
rescue => e
  raise unless ui
  ui.say "Failed processing ctags for #{spec.full_name}:\n  (#{e.class}) #{e}"
end

.invoke(languages, tag_file, *paths) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubygems/commands/ctags_command.rb', line 19

def self.invoke(languages, tag_file, *paths)
  system(
    'ctags',
    "--languages=#{languages}",
    '-R',
    '--tag-relative=yes',
    '-f',
    tag_file.to_s,
    *paths.map { |p| Pathname.new(p).relative_path_from(Pathname.pwd).to_s }
  )
end

Instance Method Details

#executeObject



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

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