Skip to content

Commit

Permalink
Check the recency of the ~/.rbenv/versions directory instead of rbenv…
Browse files Browse the repository at this point in the history
… Ruby directories to determine if Rubies have been added or removed.

This should resolve issue #19.
  • Loading branch information
carsomyr committed Jun 7, 2012
1 parent cda7262 commit a0c3d8b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ to report Bundler-installed gem executables if available.

**0.93** (May 4, 2012)

* Fix issue [#19](https://github.com/carsomyr/rbenv-bundler/issues/19), where a
crash would result from rbenv Ruby profiles not being updated to reflect the
removal of a Ruby. The `rehash.rb` script now checks the recency of the
`~/.rbenv/versions` directory instead of rbenv Ruby directories to determine
if Rubies have been added or removed.
* Fix issue [#17](https://github.com/carsomyr/rbenv-bundler/issues/17), where
the `rehash.rb` script would attempt to parse empty child process output when
building rbenv Ruby profiles. Such situations are now detected and skipped.
Expand Down
34 changes: 19 additions & 15 deletions etc/rbenv.d/bundler/rehash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ def self.read_manifest(out_dir = Pathname.new("."))
# @return [Hash] a Hash from rbenv version names to Ruby profiles.
def self.build_ruby_profiles(out_dir = Pathname.new("."))
ruby_profiles_file = Pathname.new("ruby_profiles.yml").expand_path(out_dir)
rbenv_version_dirs = Pathname.new("versions").expand_path(ENV["RBENV_ROOT"]).children
rbenv_versions_dir = Pathname.new("versions").expand_path(ENV["RBENV_ROOT"])
rbenv_version_dirs = rbenv_versions_dir.children

if ruby_profiles_file.exist? \
&& rbenv_version_dirs.select { |rbenv_version_dir| rbenv_version_dir.mtime > ruby_profiles_file.mtime }.empty?
if ruby_profiles_file.exist? && rbenv_versions_dir.mtime <= ruby_profiles_file.mtime
ruby_profiles_file.open("r") do |f|
YAML::load(f)
end
Expand All @@ -304,26 +304,30 @@ def self.build_ruby_profiles(out_dir = Pathname.new("."))
child_env["PATH"] = child_env["PATH"].split(":", -1)[1..-1].join(":")
child_env["RBENV_VERSION"] = rbenv_version

[rbenv_version, IO.popen([child_env, "ruby",
"-r", "rubygems",
"-e", "puts RUBY_VERSION\n" \
"puts Gem.dir\n" \
"puts Gem.ruby_engine\n" \
"puts Gem::ConfigMap[:ruby_version]\n",
# Ruby 1.8 compatibility: Declare Hashes explicitly when embedded in Array literals.
{:unsetenv_others => true}]) do |child_out|
ruby_profile = IO.popen([child_env, "ruby",
"-r", "rubygems",
"-e", "puts RUBY_VERSION\n" \
"puts Gem.dir\n" \
"puts Gem.ruby_engine\n" \
"puts Gem::ConfigMap[:ruby_version]\n",
# Ruby 1.8 compatibility: Declare Hashes explicitly when embedded in Array literals.
{:unsetenv_others => true}]) do |child_out|
child_out_s = child_out.read

# If the child's output is empty, the rbenv Ruby is likely nonexistent.
next if child_out_s.empty?
next nil if child_out_s.empty?

values = child_out_s.split("\n", -1)[0...-1]
OpenStruct.new(:ruby_version => values[0].split(".", -1).map { |s| s.to_i },
:gem_dir => Pathname.new(values[1]),
:gem_ruby_engine => values[2],
:gem_ruby_version => values[3])
end]
end]
end

next nil if !ruby_profile

[rbenv_version, ruby_profile]
end.select { |entry| !entry.nil? }]

ruby_profiles_file.open("w") do |f|
YAML::dump(ruby_profile_map, f)
Expand All @@ -341,7 +345,7 @@ def self.ensure_capable_ruby(ruby_profile_map)
# Find all Rubies that are 1.9+ and are not JRuby (no Kernel.fork).
rbenv_versions = ruby_profile_map.select do |rbenv_version, ruby_profile|
(ruby_profile.ruby_version <=> [1, 9]) >= 0 && ruby_profile.gem_ruby_engine != "jruby"
end.to_a.map do |entry|
end.map do |entry|
entry[0]
end.sort

Expand Down

0 comments on commit a0c3d8b

Please # to comment.