aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/path_support.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/path_support.rb')
-rw-r--r--lib/rubygems/path_support.rb36
1 files changed, 13 insertions, 23 deletions
diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb
index afb559d472..618bc793c4 100644
--- a/lib/rubygems/path_support.rb
+++ b/lib/rubygems/path_support.rb
@@ -22,21 +22,16 @@ class Gem::PathSupport
# Constructor. Takes a single argument which is to be treated like a
# hashtable, or defaults to ENV, the system environment.
#
- def initialize(env=ENV)
- @env = env
-
- # note 'env' vs 'ENV'...
- @home = env["GEM_HOME"] || ENV["GEM_HOME"] || Gem.default_dir
+ def initialize(env)
+ @home = env["GEM_HOME"] || Gem.default_dir
if File::ALT_SEPARATOR then
@home = @home.gsub(File::ALT_SEPARATOR, File::SEPARATOR)
end
- self.path = env["GEM_PATH"] || ENV["GEM_PATH"]
+ @path = split_gem_path env["GEM_PATH"], @home
- @spec_cache_dir =
- env["GEM_SPEC_CACHE"] || ENV["GEM_SPEC_CACHE"] ||
- Gem.default_spec_cache_dir
+ @spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir
@spec_cache_dir = @spec_cache_dir.dup.untaint
end
@@ -44,24 +39,19 @@ class Gem::PathSupport
private
##
- # Set the Gem search path (as reported by Gem.path).
+ # Split the Gem search path (as reported by Gem.path).
- def path=(gpaths)
+ def split_gem_path gpaths, home
# FIX: it should be [home, *path], not [*path, home]
gem_path = []
- # FIX: I can't tell wtf this is doing.
- gpaths ||= (ENV['GEM_PATH'] || "").empty? ? nil : ENV["GEM_PATH"]
-
if gpaths
- if gpaths.kind_of?(Array)
- gem_path = gpaths.dup
- else
- gem_path = gpaths.split(Gem.path_separator)
- if gpaths.end_with?(Gem.path_separator)
- gem_path += default_path
- end
+ gem_path = gpaths.split(Gem.path_separator)
+ # Handle the path_separator being set to a regexp, which will cause
+ # end_with? to error
+ if gpaths =~ /#{Gem.path_separator}\z/
+ gem_path += default_path
end
if File::ALT_SEPARATOR then
@@ -70,12 +60,12 @@ class Gem::PathSupport
end
end
- gem_path << @home
+ gem_path << home
else
gem_path = default_path
end
- @path = gem_path.uniq
+ gem_path.uniq
end
# Return the default Gem path