This avoids running `rbenv rehash` after installing libraries that don't
have executables, or after a no-op `bundle install` that didn't install
anything.
This is an attempt to work around the fact that Rubygems post_install
hooks may happen multiple times per single `bundle install` and ideally
we want `rbenv rehash` to run only once if new gems have been installed.
However, due to Bundler parallelism using `fork` on platforms that
support it, it's impossible for the child processes to communicate with
the master process to signal it to run `rbenv rehash` in the end.
This hooks into Bundler `install` command and runs `rbenv rehash` after
all gems have finished installing, but only if the install location was
system gems location and not a custom path (such as per-project
`vendor/bundle`).
This is limited because we can't tell whether any gems have been
installed at all, let alone do those gems have executables. However it's
better than having multiple `rbenv rehash` being run in parallel and
outputting confusing error messages as a result.
As it seems, JRuby 1.7 complains on stderr every time you invoke `system`:
warning: executable? does not in this environment and will return a dummy value
It doesn't seem to complain when backtics are used. It's safe to use
backticks here because `rbenv rehash` doesn't output anything on stdout,
and the exit status of the command is irrelevant.
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.