Class: Gem::PathSupport

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/path_support.rb

Overview

Gem::PathSupport facilitates the GEM_HOME and GEM_PATH environment settings to the rest of RubyGems.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ PathSupport

Constructor. Takes a single argument which is to be treated like a hashtable, or defaults to ENV, the system environment.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubygems/path_support.rb', line 30

def initialize(env)
  # Current implementation of @home, which is exposed as `Gem.paths.home`:
  # 1. If `env["GEM_HOME"]` is defined in the environment: `env["GEM_HOME"]`.
  # 2. If `Gem.default_dir` is writable: `Gem.default_dir`.
  # 3. Otherwise: `Gem.user_dir`.

  if env.key?("GEM_HOME")
    @home = normalize_home_dir(env["GEM_HOME"])
  elsif File.writable?(Gem.default_dir)
    @home = normalize_home_dir(Gem.default_dir)
  else
    # If `GEM_HOME` is not set AND we can't use `Gem.default_dir`,
    # default to a user installation and set `@auto_user_install`.
    @auto_user_install = true
    @home = normalize_home_dir(Gem.user_dir)
  end

  @path = split_gem_path env["GEM_PATH"], @home

  @spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir

  @spec_cache_dir = @spec_cache_dir.dup.tap(&Gem::UNTAINT)
end

Instance Attribute Details

#auto_user_installObject (readonly)

Whether ‘Gem.paths.home` defaulted to a user install or not.



23
24
25
# File 'lib/rubygems/path_support.rb', line 23

def auto_user_install
  @auto_user_install
end

#homeObject (readonly)

The default system path for managing Gems.



11
12
13
# File 'lib/rubygems/path_support.rb', line 11

def home
  @home
end

#pathObject (readonly)

Array of paths to search for Gems.



15
16
17
# File 'lib/rubygems/path_support.rb', line 15

def path
  @path
end

#spec_cache_dirObject (readonly)

Directory with spec cache



19
20
21
# File 'lib/rubygems/path_support.rb', line 19

def spec_cache_dir
  @spec_cache_dir
end