From 67f429c41de851052950ffdb372fda90a21a4356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 16 Oct 2014 16:33:22 +0200 Subject: [PATCH] Bring automatic gem-rehash functionality to rbenv core This bakes in the functionality of rbenv-gem-rehash plugin. The Rubygems hook is improved: - It will not rehash for gems installed in locations that rbenv otherwise doesn't search for binstubs; for instance in case of `bundle --path vendor/bundle`. - It rescues exceptions and makes them non-lethal by warning on stderr. --- rbenv.d/exec/gem-rehash.bash | 1 + rbenv.d/exec/gem-rehash/rubygems_plugin.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 rbenv.d/exec/gem-rehash.bash create mode 100644 rbenv.d/exec/gem-rehash/rubygems_plugin.rb diff --git a/rbenv.d/exec/gem-rehash.bash b/rbenv.d/exec/gem-rehash.bash new file mode 100644 index 00000000..99614b53 --- /dev/null +++ b/rbenv.d/exec/gem-rehash.bash @@ -0,0 +1 @@ +export RUBYLIB="${BASH_SOURCE%.bash}:$RUBYLIB" diff --git a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb new file mode 100644 index 00000000..e1d7b262 --- /dev/null +++ b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb @@ -0,0 +1,18 @@ +hook = lambda do |installer| + begin + # Ignore gems that aren't installed in locations that rbenv searches for binstubs + if installer.spec.executables.any? && + [Gem.default_bindir, Gem.bindir(Gem.user_dir)].include?(installer.bin_dir) + system "rbenv", "rehash" + end + rescue + warn "rbenv: error in gem-rehash (#{$!})" + end +end + +begin + Gem.post_install(&hook) + Gem.post_uninstall(&hook) +rescue + warn "rbenv: error installing gem-rehash hooks (#{$!})" +end