|
1 | 1 | require 'rdoc/ri'
|
2 | 2 |
|
3 | 3 | ##
|
4 |
| -# The directories where ri data lives. |
| 4 | +# The directories where ri data lives. Paths can be enumerated via ::each, or |
| 5 | +# queried individually via ::system_dir, ::site_dir, ::home_dir and ::gem_dir. |
5 | 6 |
|
6 | 7 | module RDoc::RI::Paths
|
7 | 8 |
|
@@ -10,15 +11,12 @@ module RDoc::RI::Paths
|
10 | 11 |
|
11 | 12 | version = RbConfig::CONFIG['ruby_version']
|
12 | 13 |
|
13 |
| -base = if RbConfig::CONFIG.key? 'ridir' then |
| 14 | +BASE = if RbConfig::CONFIG.key? 'ridir' then |
14 | 15 | File.join RbConfig::CONFIG['ridir'], version
|
15 | 16 | else
|
16 | 17 | File.join RbConfig::CONFIG['datadir'], 'ri', version
|
17 | 18 | end
|
18 | 19 |
|
19 |
| -SYSDIR = File.join base, "system" |
20 |
| -SITEDIR = File.join base, "site" |
21 |
| - |
22 | 20 | homedir = begin
|
23 | 21 | File.expand_path('~')
|
24 | 22 | rescue ArgumentError
|
@@ -47,14 +45,16 @@ module RDoc::RI::Paths
|
47 | 45 | # :extra:: ri data directory from the command line. Yielded for each
|
48 | 46 | # entry in +extra_dirs+
|
49 | 47 |
|
50 |
| -def self.each system, site, home, gems, *extra_dirs # :yields: directory, type |
| 48 | +def self.each system = true, site = true, home = true, gems = true, *extra_dirs # :yields: directory, type |
| 49 | +return enum_for __method__ unless block_given? |
| 50 | + |
51 | 51 | extra_dirs.each do |dir|
|
52 | 52 | yield dir, :extra
|
53 | 53 | end
|
54 | 54 |
|
55 |
| -yield SYSDIR, :system if system |
56 |
| -yield SITEDIR, :site if site |
57 |
| -yield HOMEDIR, :home if home and HOMEDIR |
| 55 | +yield system_dir, :system if system |
| 56 | +yield site_dir, :site if site |
| 57 | +yield home_dir, :home if home and HOMEDIR |
58 | 58 |
|
59 | 59 | gemdirs.each do |dir|
|
60 | 60 | yield dir, :gem
|
@@ -63,6 +63,17 @@ def self.each system, site, home, gems, *extra_dirs # :yields: directory, type
|
63 | 63 | nil
|
64 | 64 | end
|
65 | 65 |
|
| 66 | +## |
| 67 | +# The ri directory for the gem with +gem_name+. |
| 68 | + |
| 69 | +def self.gem_dir name, version |
| 70 | +req = Gem::Requirement.new "= #{version}" |
| 71 | + |
| 72 | +spec = Gem::Specification.find_by_name name, req |
| 73 | + |
| 74 | +File.join spec.doc_dir, 'ri' |
| 75 | +end |
| 76 | + |
66 | 77 | ##
|
67 | 78 | # The latest installed gems' ri directories
|
68 | 79 |
|
@@ -96,13 +107,24 @@ def self.gemdirs
|
96 | 107 | @gemdirs = []
|
97 | 108 | end
|
98 | 109 |
|
| 110 | +## |
| 111 | +# The location of the rdoc data in the user's home directory. |
| 112 | +# |
| 113 | +# Like ::system, ri data in the user's home directory is rare and predates |
| 114 | +# libraries distributed via RubyGems. ri data is rarely generated into this |
| 115 | +# directory. |
| 116 | + |
| 117 | +def self.home_dir |
| 118 | +HOMEDIR |
| 119 | +end |
| 120 | + |
99 | 121 | ##
|
100 | 122 | # Returns existing directories from the selected documentation directories
|
101 | 123 | # as an Array.
|
102 | 124 | #
|
103 | 125 | # See also ::each
|
104 | 126 |
|
105 |
| -def self.path(system, site, home, gems, *extra_dirs) |
| 127 | +def self.path(system = true, site = true, home = true, gems = true, *extra_dirs) |
106 | 128 | path = raw_path system, site, home, gems, *extra_dirs
|
107 | 129 |
|
108 | 130 | path.select { |directory| File.directory? directory }
|
@@ -124,5 +146,29 @@ def self.raw_path(system, site, home, gems, *extra_dirs)
|
124 | 146 | path.compact
|
125 | 147 | end
|
126 | 148 |
|
| 149 | +## |
| 150 | +# The location of ri data installed into the site dir. |
| 151 | +# |
| 152 | +# Historically this was available for documentation installed by ruby |
| 153 | +# libraries predating RubyGems. It is unlikely to contain any content for |
| 154 | +# modern ruby installations. |
| 155 | + |
| 156 | +def self.site_dir |
| 157 | +File.join BASE, 'site' |
| 158 | +end |
| 159 | + |
| 160 | +## |
| 161 | +# The location of the built-in ri data. |
| 162 | +# |
| 163 | +# This data is built automatically when `make` is run when ruby is |
| 164 | +# installed. If you did not install ruby by hand you may need to install |
| 165 | +# the documentation yourself. Please consult the documentation for your |
| 166 | +# package manager or ruby installer for details. You can also use the |
| 167 | +# rdoc-data gem to install system ri data for common versions of ruby. |
| 168 | + |
| 169 | +def self.system_dir |
| 170 | +File.join BASE, 'system' |
| 171 | +end |
| 172 | + |
127 | 173 | end
|
128 | 174 |
|
0 commit comments