4 # Encapsulate all the strangeness to do with finding out where to find RDoc
7 # We basically deal with three directories:
9 # 1. The 'system' documentation directory, which holds the documentation
10 # distributed with Ruby, and which is managed by the Ruby install process
11 # 2. The 'site' directory, which contains site-wide documentation added
13 # 3. The 'user' documentation directory, stored under the user's own home
16 # There's contention about all this, but for now:
18 # system:: $datadir/ri/<ver>/system/...
19 # site:: $datadir/ri/<ver>/site/...
22 module RDoc::RI::Paths
29 version = RbConfig::CONFIG['ruby_version']
31 base = File.join(RbConfig::CONFIG['datadir'], "ri", version)
32 SYSDIR = File.join(base, "system")
33 SITEDIR = File.join(base, "site")
34 homedir = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
37 HOMEDIR = File.join(homedir, ".rdoc")
42 # This is the search path for 'ri'
43 PATH = [ SYSDIR, SITEDIR, HOMEDIR ].find_all {|p| p && File.directory?(p)}
46 require 'rubygems' unless defined?(Gem) and defined?(Gem::Enable) and
49 # HACK dup'd from Gem.latest_partials and friends
52 all_paths = Gem.path.map do |dir|
53 Dir[File.join(dir, 'doc', '*', 'ri')]
58 all_paths.each do |dir|
59 base = File.basename File.dirname(dir)
60 if base =~ /(.*)-((\d+\.)*\d+)/ then
61 name, version = $1, $2
62 ver = Gem::Version.new version
63 if ri_paths[name].nil? or ver > ri_paths[name][0] then
64 ri_paths[name] = [ver, dir]
69 GEMDIRS = ri_paths.map { |k,v| v.last }.sort
70 GEMDIRS.each { |dir| PATH << dir }
75 # Returns the selected documentation directories as an Array, or PATH if no
76 # overriding directories were given.
78 def self.path(use_system, use_site, use_home, use_gems, *extra_dirs)
79 path = raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
80 return path.select { |directory| File.directory? directory }
83 # Returns the selected documentation directories including nonexistent
84 # directories. Used to print out what paths were searched if no ri was
87 def self.raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
88 return PATH unless use_system or use_site or use_home or use_gems or
92 path << extra_dirs unless extra_dirs.empty?
93 path << SYSDIR if use_system
94 path << SITEDIR if use_site
95 path << HOMEDIR if use_home
96 path << GEMDIRS if use_gems
98 return path.flatten.compact