summaryrefslogtreecommitdiff
path: root/lib/rubygems/installer_uninstaller_utils.rb
blob: b8436f4f0ab2e6b14ebf16c5901850f332a91a90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

##
# Helper methods for both Gem::Installer and Gem::Uninstaller

module Gem::InstallerUninstallerUtils

  def regenerate_plugins_for(spec)
    spec.plugins.each do |plugin|
      plugin_script_path = File.join Gem.plugins_dir, "#{spec.name}_plugin#{File.extname(plugin)}"

      File.open plugin_script_path, 'wb' do |file|
        file.puts "require '#{plugin}'"
      end

      verbose plugin_script_path
    end
  end

  def remove_plugins_for(spec)
    FileUtils.rm_f Gem::Util.glob_files_in_dir("#{spec.name}#{Gem.plugin_suffix_pattern}", Gem.plugins_dir)
  end

end