From 325abac17de79a230152bb7038126a0641c6aa64 Mon Sep 17 00:00:00 2001 From: benmelz Date: Sat, 9 Dec 2023 15:14:40 -0500 Subject: [PATCH] Move gem-rehash monkey patch (#1541) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `rubygems_plugin.rb` file doesn't get loaded until after `Bundler::Installer.install` is called, so target `Bundler::Installer#install` to fix invocation order issues. Co-authored-by: Mislav Marohnić --- rbenv.d/exec/gem-rehash/rubygems_plugin.rb | 36 ++++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb index 7ced31a..d02bca8 100644 --- a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb +++ b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb @@ -10,27 +10,29 @@ hook = lambda do |installer| end end -if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) && !Bundler::Installer.respond_to?(:install_without_rbenv_rehash) +if defined?(Bundler::Installer) && + Bundler::Installer.private_method_defined?(:install) && + !Bundler::Installer.private_method_defined?(:install_without_rbenv_rehash) Bundler::Installer.class_eval do - class << self - alias install_without_rbenv_rehash install - def install(root, definition, options = {}) - begin - if Gem.default_path.include?(Bundler.bundle_path.to_s) - bin_dir = Gem.bindir(Bundler.bundle_path.to_s) - bins_before = File.exist?(bin_dir) ? Dir.entries(bin_dir).size : 2 - end - rescue - warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})" - end + private - result = install_without_rbenv_rehash(root, definition, options) - - if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before - `rbenv rehash` + alias install_without_rbenv_rehash install + def install(options) + begin + if Gem.default_path.include?(Bundler.bundle_path.to_s) + bin_dir = Gem.bindir(Bundler.bundle_path.to_s) + bins_before = File.exist?(bin_dir) ? Dir.entries(bin_dir).size : 2 end - result + rescue + warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})" end + + result = install_without_rbenv_rehash(options) + + if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before + `rbenv rehash` + end + result end end else