-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
rubygems_plugin.rb
43 lines (40 loc) · 1.39 KB
/
rubygems_plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)
`rbenv rehash`
end
rescue
warn "rbenv: error in gem-rehash (#{$!.class.name}: #{$!.message})"
end
end
if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) && !Bundler::Installer.respond_to?(: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
result = install_without_rbenv_rehash(root, definition, options)
if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before
`rbenv rehash`
end
result
end
end
end
else
begin
Gem.post_install(&hook)
Gem.post_uninstall(&hook)
rescue
warn "rbenv: error installing gem-rehash hooks (#{$!.class.name}: #{$!.message})"
end
end