Sha256: 0e7b7eef08a8b9a80e2552fb73fb10aef1628f0d4e8d0465c9775dd32b55fe0f
Contents?: true
Size: 1.53 KB
Versions: 1
Compression:
Stored size: 1.53 KB
Contents
# frozen_string_literal: true require "pathname" require "rubygems/command" class Gem::Commands::TtagsCommand < Gem::Command def initialize super "ttags", "Generate ttags for gems" end def execute Gem::Specification.each { |spec| self.class.index(spec, ui) } end class << self def invoke(tag_file, *paths) system( "ttags", "-f", tag_file.to_s, *paths.map { |p| Pathname.new(p).relative_path_from(Pathname.pwd).to_s } ) end def can_write?(path) path.dirname.directory? && !path.directory? && !(path.file? && path.read(1) == "!") end def index(spec, ui = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength gem_path = Pathname.new(spec.full_gem_path) tag_file = gem_path.join("tags") paths = spec.require_paths.map { |p| gem_path.join(p) } puts "#{gem_path} #{paths}" if paths.any? && can_write?(tag_file) ui&.say "Generating ttags for #{spec.full_name}" invoke(tag_file, *paths) end inject(gem_path, spec, ui) rescue StandardError => e raise unless ui ui.say "Failed making tags for #{spec.full_name}:\n (#{e.class}) #{e}" end private def inject(gem_path, spec, ui) target = gem_path.join("lib/bundler/cli.rb") return unless target.writable? && !target.read.include?("load_plugins") ui&.say "Injecting gem-ttags into #{spec.full_name}" target.open("a") do |f| f.write "\nGem.load_plugins rescue nil\n" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gem-ttags-1.0.2 | lib/rubygems/commands/ttags_command.rb |