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.
This commit is contained in:
Mislav Marohnić 2014-10-16 16:33:22 +02:00
parent 632263568e
commit 67f429c41d
2 changed files with 19 additions and 0 deletions

View file

@ -0,0 +1 @@
export RUBYLIB="${BASH_SOURCE%.bash}:$RUBYLIB"

View file

@ -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