class method
Gem.activate_and_load_bin_path
activate_and_load_bin_path(name, exec_name = nil, *requirements)
lib/rubygems.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/rubygems.rb, line 281
def self.activate_and_load_bin_path(name, exec_name = nil, *requirements)
spec = find_and_activate_spec_for_exe name, exec_name, requirements
if spec.name == "bundler"
# Old versions of Bundler need a workaround to support nested `bundle
# exec` invocations by overriding `Gem.activate_bin_path`. However,
# RubyGems now uses this new `Gem.activate_and_load_bin_path` helper in
# binstubs, which is of course not overridden in Bundler since it didn't
# exist at the time. So, include the override here to workaround that.
load ENV["BUNDLE_BIN_PATH"] if ENV["BUNDLE_BIN_PATH"] && spec.version <= Gem::Version.create("2.5.22")
# Make sure there's no version of Bundler in `$LOAD_PATH` that's different
# from the version we just activated. If that was the case (it happens
# when testing Bundler from ruby/ruby), we would load Bundler extensions
# to RubyGems from the copy in `$LOAD_PATH` but then load the binstub from
# an installed copy, causing those copies to be mixed and yet more
# redefinition warnings.
#
require_path = $LOAD_PATH.resolve_feature_path("bundler").last.delete_suffix("/bundler.rb")
Gem.load_bundler_extensions(spec.version) if spec.full_require_paths.include?(require_path)
end
load spec.bin_file(exec_name)
end
Find and load the full path to the executable for gem name. If the exec_name is not given, an exception will be raised, otherwise the specified executable’s path is returned. requirements allows you to specify specific gem versions.
A side effect of this method is that it will activate the gem that contains the executable.
This method should only be used in bin stub files.