lib/bootboot/ruby_source.rb in bootboot-0.2.1 vs lib/bootboot/ruby_source.rb in bootboot-0.2.2

- old
+ new

@@ -16,18 +16,33 @@ end end def specs Bundler::Index.build do |idx| - # If the ruby version specified in the Gemfile is different from the - # Ruby version currently running, we want to build a definition without - # a lockfile (so that `ruby_version` in the Gemfile isn't overridden by - # the lockfile) and get its `ruby_version`. This will be used both - # during dependency resolution so that we can pretend the intended Ruby - # version is present, as well as when updating the lockfile itself. - ruby_version = Bundler::Definition.build(Bootboot::GEMFILE, nil, false).ruby_version - ruby_version ||= Bundler::RubyVersion.system - ruby_spec = Gem::Specification.new(ruby_spec_name, ruby_version.gem_version) + requested_ruby = Bundler::Definition.build(Bootboot::GEMFILE, nil, false).ruby_version + system_version = Bundler::RubyVersion.system.gem_version + requirement = Gem::Requirement.new(requested_ruby.versions) if requested_ruby + + # This will be used both during dependency resolution so that we can pretend + # the intended Ruby version is present, as well as when updating the lock file. + ruby_spec_version = if requested_ruby.nil? + # if the Gemfile doesn't request a specific Ruby version, just use system + system_version + elsif !requirement.exact? && requirement.satisfied_by?(system_version) + # if the Gemfile requests a non-exact Ruby version which is satisfied by + # the currently running Ruby, use that when updating the lock file + system_version + else + # If we're here, there's either an exact requirement for the Ruby version + # (in which case we should substitue it instead of current Ruby version), + # else the currently running Ruby doesn't satisfy the non-exact requirement + # (in which case an error will be thrown by bundler). Not sure how we can + # improve the error message, which will be vague due to using #gem_version + # of the unsatisified requirement. + requested_ruby.gem_version + end + + ruby_spec = Gem::Specification.new(ruby_spec_name, ruby_spec_version) ruby_spec.source = self idx << ruby_spec end end