5 # Returns full path of previous but one directory of dir in path
6 # E.g. for '/usr/share/ruby', 'ruby', it returns '/usr'
8 def previous_but_one_dir_to(path, dir)
9 split_path = path.split(File::SEPARATOR)
10 File.join(split_path.take_while { |one_dir| one_dir !~ /^#{dir}$/ }[0..-2])
12 private :previous_but_one_dir_to
15 # Default gems locations allowed on FHS system (/usr, /usr/share).
16 # The locations are derived from directories specified during build
20 @default_locations ||= {
21 :system => previous_but_one_dir_to(ConfigMap[:vendordir], ConfigMap[:RUBY_INSTALL_NAME]),
22 :local => previous_but_one_dir_to(ConfigMap[:sitedir], ConfigMap[:RUBY_INSTALL_NAME])
27 # For each location provides set of directories for binaries (:bin_dir)
28 # platform independent (:gem_dir) and dependent (:ext_dir) files.
31 @libdir ||= case RUBY_PLATFORM
38 @default_dirs ||= Hash[default_locations.collect do |destination, path|
40 :bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
41 :gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
42 :ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
48 # Remove methods we are going to override. This avoids "method redefined;"
49 # warnings otherwise issued by Ruby.
51 remove_method :default_dir if method_defined? :default_dir
52 remove_method :default_path if method_defined? :default_path
53 remove_method :default_bindir if method_defined? :default_bindir
54 remove_method :default_ext_dir_for if method_defined? :default_ext_dir_for
57 # RubyGems default overrides.
61 Gem.default_dirs[:local][:gem_dir]
68 path = default_dirs.collect {|location, paths| paths[:gem_dir]}
69 path.unshift Gem.user_dir if File.exist? Gem.user_home
74 Gem.default_dirs[:local][:bin_dir]
76 File.join [Dir.home, 'bin']
80 def default_ext_dir_for base_dir
81 dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
82 dirs && File.join(dirs.last[:ext_dir], RbConfig::CONFIG['RUBY_INSTALL_NAME'])