2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2011-05-31 23:45:05 -04:00
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
#
|
2011-05-31 23:45:05 -04:00
|
|
|
# Gem::PathSupport facilitates the GEM_HOME and GEM_PATH environment settings
|
|
|
|
# to the rest of RubyGems.
|
|
|
|
#
|
|
|
|
class Gem::PathSupport
|
|
|
|
##
|
|
|
|
# The default system path for managing Gems.
|
|
|
|
attr_reader :home
|
|
|
|
|
|
|
|
##
|
|
|
|
# Array of paths to search for Gems.
|
|
|
|
attr_reader :path
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Directory with spec cache
|
|
|
|
attr_reader :spec_cache_dir # :nodoc:
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Constructor. Takes a single argument which is to be treated like a
|
|
|
|
# hashtable, or defaults to ENV, the system environment.
|
|
|
|
#
|
2016-03-03 19:29:40 -05:00
|
|
|
def initialize(env)
|
|
|
|
@home = env["GEM_HOME"] || Gem.default_dir
|
2011-07-26 21:40:07 -04:00
|
|
|
|
|
|
|
if File::ALT_SEPARATOR then
|
|
|
|
@home = @home.gsub(File::ALT_SEPARATOR, File::SEPARATOR)
|
|
|
|
end
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
@path = split_gem_path env["GEM_PATH"], @home
|
2013-09-14 04:59:02 -04:00
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
@spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir
|
2013-09-14 04:59:02 -04:00
|
|
|
|
|
|
|
@spec_cache_dir = @spec_cache_dir.dup.untaint
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
##
|
2016-03-03 19:29:40 -05:00
|
|
|
# Split the Gem search path (as reported by Gem.path).
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
def split_gem_path gpaths, home
|
2012-11-29 01:52:18 -05:00
|
|
|
# FIX: it should be [home, *path], not [*path, home]
|
|
|
|
|
|
|
|
gem_path = []
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
if gpaths
|
2016-03-03 19:29:40 -05:00
|
|
|
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
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if File::ALT_SEPARATOR then
|
|
|
|
gem_path.map! do |this_path|
|
|
|
|
this_path.gsub File::ALT_SEPARATOR, File::SEPARATOR
|
|
|
|
end
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
gem_path << home
|
2011-05-31 23:45:05 -04:00
|
|
|
else
|
2016-02-01 07:43:26 -05:00
|
|
|
gem_path = default_path
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
gem_path.uniq
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
2016-02-01 07:43:26 -05:00
|
|
|
|
|
|
|
# Return the default Gem path
|
|
|
|
def default_path
|
|
|
|
gem_path = Gem.default_path + [@home]
|
|
|
|
|
|
|
|
if defined?(APPLE_GEM_HOME)
|
|
|
|
gem_path << APPLE_GEM_HOME
|
|
|
|
end
|
|
|
|
gem_path
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|