# E.g. for '/usr/share/ruby', 'ruby', it returns '/usr'
def previous_but_one_dir_to(path, dir)
+ return unless path
+
split_path = path.split(File::SEPARATOR)
File.join(split_path.take_while { |one_dir| one_dir !~ /^#{dir}$/ }[0..-2])
end
def default_locations
@default_locations ||= {
- :system => previous_but_one_dir_to(ConfigMap[:vendordir], ConfigMap[:RUBY_INSTALL_NAME]),
- :local => previous_but_one_dir_to(ConfigMap[:sitedir], ConfigMap[:RUBY_INSTALL_NAME])
+ :system => previous_but_one_dir_to(RbConfig::CONFIG['vendordir'], RbConfig::CONFIG['RUBY_INSTALL_NAME']),
+ :local => previous_but_one_dir_to(RbConfig::CONFIG['sitedir'], RbConfig::CONFIG['RUBY_INSTALL_NAME'])
}
end
def default_dirs
@libdir ||= case RUBY_PLATFORM
when 'java'
- ConfigMap[:datadir]
+ RbConfig::CONFIG['datadir']
else
- ConfigMap[:libdir]
+ RbConfig::CONFIG['libdir']
end
- @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, @libdir.split(File::SEPARATOR).last, 'gems')
- }]
- end]
+ @default_dirs ||= default_locations.inject(Hash.new) do |hash, location|
+ destination, path = location
+
+ hash[destination] = if path
+ {
+ :bin_dir => File.join(path, RbConfig::CONFIG['bindir'].split(File::SEPARATOR).last),
+ :gem_dir => File.join(path, RbConfig::CONFIG['datadir'].split(File::SEPARATOR).last, 'gems'),
+ :ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
+ }
+ else
+ {
+ :bin_dir => '',
+ :gem_dir => '',
+ :ext_dir => ''
+ }
+ end
+
+ hash
+ end
end
##