-
Notifications
You must be signed in to change notification settings - Fork 0
/
operating_system.rb
70 lines (59 loc) · 2.08 KB
/
operating_system.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Gem
class << self
##
# Returns a string representing that part or the directory tree that is
# common to all specified directories.
def common_path(dirs)
paths = dirs.collect {|dir| dir.split(File::SEPARATOR)}
uncommon_idx = paths.transpose.each_with_index.find {|dirnames, idx| dirnames.uniq.length > 1}.last
paths[0][0 ... uncommon_idx].join(File::SEPARATOR)
end
private :common_path
##
# Default gems locations allowed on FHS system (/usr, /usr/share).
# The locations are derived from directories specified during build
# configuration.
def default_locations
@default_locations ||= {
:system => common_path([ConfigMap[:vendorlibdir], ConfigMap[:vendorarchdir]]),
:local => common_path([ConfigMap[:sitelibdir], ConfigMap[:sitearchdir]])
}
end
##
# For each location provides set of directories for binaries (:bin_dir)
# platform independent (:gem_dir) and dependent (:ext_dir) files.
def default_dirs
@default_dirs ||= Hash[default_locations.collect do |destination, path|
[destination, {
:bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
:gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
:ext_dir => File.join(path, ConfigMap[:libdir].split(File::SEPARATOR).last, 'gems')
}]
end]
end
##
# RubyGems default overrides.
def default_dir
if Process.uid == 0
Gem.default_dirs[:local][:gem_dir]
else
Gem.user_dir
end
end
def default_path
path = default_dirs.collect {|location, paths| paths[:gem_dir]}
path.unshift Gem.user_dir if File.exist? Gem.user_home
end
def default_bindir
if Process.uid == 0
Gem.default_dirs[:local][:bin_dir]
else
File.join [Dir.home, 'bin']
end
end
def default_ext_dir_for base_dir
dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
dirs && File.join(dirs.last[:ext_dir], 'exts')
end
end
end