summaryrefslogtreecommitdiff
path: root/lib/rubygems.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems.rb')
-rw-r--r--lib/rubygems.rb26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index e25e05a3b8..9549b9bdca 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -290,6 +290,24 @@ module Gem
@ruby
end
+ # Return the index to insert activated gem paths into the $LOAD_PATH
+ # Defaults to the site lib directory unless gem_prelude.rb has loaded
+ # paths then it inserts the path before those paths so you can override
+ # the gem_prelude.rb default $LOAD_PATH paths.
+ def load_path_insert_index
+ index = $LOAD_PATH.index ConfigMap[:sitelibdir]
+
+ $LOAD_PATH.each_with_index do |path, i|
+ if path.instance_variables.include?(:@gem_prelude_index) or
+ path.instance_variables.include?('@gem_prelude_index') then
+ index = i
+ break
+ end
+ end
+
+ index
+ end
+
# Activate a gem (i.e. add it to the Ruby load path). The gem
# must satisfy all the specified version constraints. If
# +autorequire+ is true, then automatically require the specified
@@ -345,11 +363,13 @@ module Gem
end
sitelibdir = ConfigMap[:sitelibdir]
- sitelibdir_index = $LOAD_PATH.index sitelibdir
- if sitelibdir_index then
+ # gem directories must come after -I and ENV['RUBYLIB']
+ insert_index = load_path_insert_index
+
+ if insert_index then
# gem directories must come after -I and ENV['RUBYLIB']
- $LOAD_PATH.insert(sitelibdir_index, *require_paths)
+ $LOAD_PATH.insert(insert_index, *require_paths)
else
# we are probably testing in core, -I and RUBYLIB don't apply
$LOAD_PATH.unshift(*require_paths)