rdoc 3.12.2 → 4.0.0.preview2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (200) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +3 -2
  5. data/DEVELOPERS.rdoc +53 -0
  6. data/History.rdoc +159 -25
  7. data/LEGAL.rdoc +12 -0
  8. data/Manifest.txt +56 -3
  9. data/README.rdoc +87 -19
  10. data/Rakefile +11 -2
  11. data/TODO.rdoc +20 -13
  12. data/bin/rdoc +4 -0
  13. data/lib/gauntlet_rdoc.rb +1 -1
  14. data/lib/rdoc.rb +32 -71
  15. data/lib/rdoc/any_method.rb +75 -21
  16. data/lib/rdoc/attr.rb +49 -10
  17. data/lib/rdoc/class_module.rb +182 -32
  18. data/lib/rdoc/code_object.rb +54 -12
  19. data/lib/rdoc/comment.rb +8 -1
  20. data/lib/rdoc/constant.rb +100 -6
  21. data/lib/rdoc/context.rb +93 -41
  22. data/lib/rdoc/context/section.rb +143 -28
  23. data/lib/rdoc/cross_reference.rb +58 -50
  24. data/lib/rdoc/encoding.rb +34 -29
  25. data/lib/rdoc/erb_partial.rb +18 -0
  26. data/lib/rdoc/extend.rb +117 -0
  27. data/lib/rdoc/generator.rb +11 -6
  28. data/lib/rdoc/generator/darkfish.rb +250 -62
  29. data/lib/rdoc/generator/json_index.rb +20 -12
  30. data/lib/rdoc/generator/markup.rb +10 -12
  31. data/lib/rdoc/generator/ri.rb +7 -60
  32. data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
  39. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
  41. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
  42. data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
  43. data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
  44. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  45. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
  46. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  47. data/lib/rdoc/include.rb +12 -3
  48. data/lib/rdoc/markdown.kpeg +1186 -0
  49. data/lib/rdoc/markdown.rb +16336 -0
  50. data/lib/rdoc/markdown/entities.rb +2128 -0
  51. data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
  52. data/lib/rdoc/markdown/literals_1_8.rb +454 -0
  53. data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
  54. data/lib/rdoc/markdown/literals_1_9.rb +417 -0
  55. data/lib/rdoc/markup.rb +69 -10
  56. data/lib/rdoc/markup/attr_changer.rb +2 -5
  57. data/lib/rdoc/markup/attribute_manager.rb +23 -14
  58. data/lib/rdoc/markup/attributes.rb +70 -0
  59. data/lib/rdoc/markup/block_quote.rb +14 -0
  60. data/lib/rdoc/markup/document.rb +20 -4
  61. data/lib/rdoc/markup/formatter.rb +17 -6
  62. data/lib/rdoc/markup/formatter_test_case.rb +93 -24
  63. data/lib/rdoc/markup/hard_break.rb +31 -0
  64. data/lib/rdoc/markup/heading.rb +1 -1
  65. data/lib/rdoc/markup/indented_paragraph.rb +14 -0
  66. data/lib/rdoc/markup/list.rb +23 -4
  67. data/lib/rdoc/markup/list_item.rb +17 -4
  68. data/lib/rdoc/markup/paragraph.rb +14 -0
  69. data/lib/rdoc/markup/parser.rb +107 -60
  70. data/lib/rdoc/markup/raw.rb +4 -4
  71. data/lib/rdoc/markup/special.rb +3 -3
  72. data/lib/rdoc/markup/to_ansi.rb +7 -1
  73. data/lib/rdoc/markup/to_html.rb +42 -14
  74. data/lib/rdoc/markup/to_html_crossref.rb +10 -9
  75. data/lib/rdoc/markup/to_html_snippet.rb +20 -4
  76. data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
  77. data/lib/rdoc/markup/to_label.rb +20 -1
  78. data/lib/rdoc/markup/to_markdown.rb +134 -0
  79. data/lib/rdoc/markup/to_rdoc.rb +36 -5
  80. data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
  81. data/lib/rdoc/markup/to_tt_only.rb +11 -2
  82. data/lib/rdoc/markup/verbatim.rb +19 -0
  83. data/lib/rdoc/method_attr.rb +33 -19
  84. data/lib/rdoc/normal_class.rb +26 -7
  85. data/lib/rdoc/normal_module.rb +10 -5
  86. data/lib/rdoc/options.rb +95 -21
  87. data/lib/rdoc/parser.rb +6 -2
  88. data/lib/rdoc/parser/c.rb +212 -97
  89. data/lib/rdoc/parser/markdown.rb +23 -0
  90. data/lib/rdoc/parser/ruby.rb +115 -35
  91. data/lib/rdoc/parser/ruby_tools.rb +8 -3
  92. data/lib/rdoc/rd.rb +8 -4
  93. data/lib/rdoc/rd/block_parser.rb +1 -1
  94. data/lib/rdoc/rd/block_parser.ry +1 -1
  95. data/lib/rdoc/rdoc.rb +45 -21
  96. data/lib/rdoc/ri/driver.rb +322 -76
  97. data/lib/rdoc/ri/paths.rb +90 -31
  98. data/lib/rdoc/ri/store.rb +2 -353
  99. data/lib/rdoc/ruby_lex.rb +5 -21
  100. data/lib/rdoc/ruby_token.rb +2 -3
  101. data/lib/rdoc/rubygems_hook.rb +21 -9
  102. data/lib/rdoc/servlet.rb +302 -0
  103. data/lib/rdoc/stats.rb +28 -20
  104. data/lib/rdoc/store.rb +881 -0
  105. data/lib/rdoc/task.rb +2 -1
  106. data/lib/rdoc/test_case.rb +103 -1
  107. data/lib/rdoc/text.rb +5 -4
  108. data/lib/rdoc/tom_doc.rb +17 -16
  109. data/lib/rdoc/top_level.rb +43 -285
  110. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
  111. data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
  112. data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
  113. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
  114. data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
  115. data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
  116. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
  117. data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
  118. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
  119. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
  120. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
  121. data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
  122. data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
  123. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
  124. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
  125. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
  126. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
  127. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
  128. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
  129. data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
  130. data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
  131. data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
  132. data/test/test_attribute_manager.rb +7 -4
  133. data/test/test_rdoc_any_method.rb +84 -13
  134. data/test/test_rdoc_attr.rb +59 -9
  135. data/test/test_rdoc_class_module.rb +670 -73
  136. data/test/test_rdoc_code_object.rb +21 -1
  137. data/test/test_rdoc_comment.rb +1 -1
  138. data/test/test_rdoc_constant.rb +132 -0
  139. data/test/test_rdoc_context.rb +84 -18
  140. data/test/test_rdoc_context_section.rb +99 -15
  141. data/test/test_rdoc_cross_reference.rb +1 -1
  142. data/test/test_rdoc_encoding.rb +17 -1
  143. data/test/test_rdoc_extend.rb +94 -0
  144. data/test/test_rdoc_generator_darkfish.rb +45 -19
  145. data/test/test_rdoc_generator_json_index.rb +27 -7
  146. data/test/test_rdoc_generator_markup.rb +3 -3
  147. data/test/test_rdoc_generator_ri.rb +11 -9
  148. data/test/test_rdoc_include.rb +12 -0
  149. data/test/test_rdoc_markdown.rb +977 -0
  150. data/test/test_rdoc_markdown_test.rb +1891 -0
  151. data/test/test_rdoc_markup.rb +1 -1
  152. data/test/test_rdoc_markup_attribute_manager.rb +2 -2
  153. data/test/test_rdoc_markup_attributes.rb +39 -0
  154. data/test/test_rdoc_markup_document.rb +16 -1
  155. data/test/test_rdoc_markup_formatter.rb +7 -4
  156. data/test/test_rdoc_markup_hard_break.rb +31 -0
  157. data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
  158. data/test/test_rdoc_markup_paragraph.rb +15 -1
  159. data/test/test_rdoc_markup_parser.rb +152 -89
  160. data/test/test_rdoc_markup_to_ansi.rb +23 -2
  161. data/test/test_rdoc_markup_to_bs.rb +24 -0
  162. data/test/test_rdoc_markup_to_html.rb +50 -19
  163. data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
  164. data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
  165. data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
  166. data/test/test_rdoc_markup_to_label.rb +63 -1
  167. data/test/test_rdoc_markup_to_markdown.rb +352 -0
  168. data/test/test_rdoc_markup_to_rdoc.rb +22 -2
  169. data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
  170. data/test/test_rdoc_markup_to_tt_only.rb +20 -0
  171. data/test/test_rdoc_markup_verbatim.rb +13 -0
  172. data/test/test_rdoc_method_attr.rb +5 -0
  173. data/test/test_rdoc_normal_class.rb +24 -5
  174. data/test/test_rdoc_normal_module.rb +1 -1
  175. data/test/test_rdoc_options.rb +21 -6
  176. data/test/test_rdoc_parser.rb +24 -0
  177. data/test/test_rdoc_parser_c.rb +151 -26
  178. data/test/test_rdoc_parser_markdown.rb +55 -0
  179. data/test/test_rdoc_parser_rd.rb +2 -2
  180. data/test/test_rdoc_parser_ruby.rb +468 -109
  181. data/test/test_rdoc_parser_simple.rb +2 -2
  182. data/test/test_rdoc_rd_block_parser.rb +0 -4
  183. data/test/test_rdoc_rdoc.rb +110 -22
  184. data/test/test_rdoc_ri_driver.rb +415 -80
  185. data/test/test_rdoc_ri_paths.rb +122 -13
  186. data/test/test_rdoc_ruby_lex.rb +5 -61
  187. data/test/test_rdoc_ruby_token.rb +19 -0
  188. data/test/test_rdoc_rubygems_hook.rb +64 -43
  189. data/test/test_rdoc_servlet.rb +429 -0
  190. data/test/test_rdoc_stats.rb +83 -24
  191. data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
  192. data/test/test_rdoc_task.rb +2 -2
  193. data/test/test_rdoc_text.rb +37 -11
  194. data/test/test_rdoc_tom_doc.rb +59 -62
  195. data/test/test_rdoc_top_level.rb +71 -113
  196. data/test/xref_test_case.rb +7 -9
  197. metadata +122 -39
  198. metadata.gz.sig +0 -0
  199. data/CVE-2013-0256.rdoc +0 -49
  200. data/lib/rdoc/markup/attribute.rb +0 -51
@@ -1,7 +1,8 @@
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
@@ -32,8 +30,6 @@ module RDoc::RI::Paths
32
30
  end
33
31
  #:startdoc:
34
32
 
35
- @gemdirs = nil
36
-
37
33
  ##
38
34
  # Iterates over each selected path yielding the directory and type.
39
35
  #
@@ -47,16 +43,19 @@ module RDoc::RI::Paths
47
43
  # :extra:: ri data directory from the command line. Yielded for each
48
44
  # entry in +extra_dirs+
49
45
 
50
- def self.each system, site, home, gems, *extra_dirs # :yields: directory, type
46
+ def self.each system = true, site = true, home = true, gems = :latest, *extra_dirs # :yields: directory, type
47
+ return enum_for __method__, system, site, home, gems, *extra_dirs unless
48
+ block_given?
49
+
51
50
  extra_dirs.each do |dir|
52
51
  yield dir, :extra
53
52
  end
54
53
 
55
- yield SYSDIR, :system if system
56
- yield SITEDIR, :site if site
57
- yield HOMEDIR, :home if home and HOMEDIR
54
+ yield system_dir, :system if system
55
+ yield site_dir, :site if site
56
+ yield home_dir, :home if home and HOMEDIR
58
57
 
59
- gemdirs.each do |dir|
58
+ gemdirs(gems).each do |dir|
60
59
  yield dir, :gem
61
60
  end if gems
62
61
 
@@ -64,36 +63,72 @@ module RDoc::RI::Paths
64
63
  end
65
64
 
66
65
  ##
67
- # The latest installed gems' ri directories
66
+ # The ri directory for the gem with +gem_name+.
68
67
 
69
- def self.gemdirs
70
- return @gemdirs if @gemdirs
68
+ def self.gem_dir name, version
69
+ req = Gem::Requirement.new "= #{version}"
71
70
 
72
- require 'rubygems' unless defined?(Gem)
71
+ spec = Gem::Specification.find_by_name name, req
73
72
 
74
- # HACK dup'd from Gem.latest_partials and friends
75
- all_paths = []
73
+ File.join spec.doc_dir, 'ri'
74
+ end
76
75
 
77
- all_paths = Gem.path.map do |dir|
78
- Dir[File.join(dir, 'doc', '*', 'ri')]
79
- end.flatten
76
+ ##
77
+ # The latest installed gems' ri directories. +filter+ can be :all or
78
+ # :latest.
79
+ #
80
+ # A +filter+ :all includes all versions of gems and includes gems without
81
+ # ri documentation.
82
+
83
+ def self.gemdirs filter = :latest
84
+ require 'rubygems' unless defined?(Gem)
80
85
 
81
86
  ri_paths = {}
82
87
 
83
- all_paths.each do |dir|
84
- base = File.basename File.dirname(dir)
85
- if base =~ /(.*)-((\d+\.)*\d+)/ then
86
- name, version = $1, $2
87
- ver = Gem::Version.new version
88
- if ri_paths[name].nil? or ver > ri_paths[name][0] then
89
- ri_paths[name] = [ver, dir]
88
+ all = Gem::Specification.map do |spec|
89
+ [File.join(spec.doc_dir, 'ri'), spec.name, spec.version]
90
+ end
91
+
92
+ if filter == :all then
93
+ gemdirs = []
94
+
95
+ all.group_by do |_, name, _|
96
+ name
97
+ end.sort_by do |group, _|
98
+ group
99
+ end.map do |group, items|
100
+ items.sort_by do |_, _, version|
101
+ version
102
+ end.reverse_each do |dir,|
103
+ gemdirs << dir
90
104
  end
91
105
  end
106
+
107
+ return gemdirs
108
+ end
109
+
110
+ all.each do |dir, name, ver|
111
+ next unless File.exist? dir
112
+
113
+ if ri_paths[name].nil? or ver > ri_paths[name].first then
114
+ ri_paths[name] = [ver, name, dir]
115
+ end
92
116
  end
93
117
 
94
- @gemdirs = ri_paths.map { |k,v| v.last }.sort
118
+ ri_paths.sort_by { |_, (_, name, _)| name }.map { |k, v| v.last }
95
119
  rescue LoadError
96
- @gemdirs = []
120
+ []
121
+ end
122
+
123
+ ##
124
+ # The location of the rdoc data in the user's home directory.
125
+ #
126
+ # Like ::system, ri data in the user's home directory is rare and predates
127
+ # libraries distributed via RubyGems. ri data is rarely generated into this
128
+ # directory.
129
+
130
+ def self.home_dir
131
+ HOMEDIR
97
132
  end
98
133
 
99
134
  ##
@@ -102,7 +137,7 @@ module RDoc::RI::Paths
102
137
  #
103
138
  # See also ::each
104
139
 
105
- def self.path(system, site, home, gems, *extra_dirs)
140
+ def self.path(system = true, site = true, home = true, gems = :latest, *extra_dirs)
106
141
  path = raw_path system, site, home, gems, *extra_dirs
107
142
 
108
143
  path.select { |directory| File.directory? directory }
@@ -124,5 +159,29 @@ module RDoc::RI::Paths
124
159
  path.compact
125
160
  end
126
161
 
162
+ ##
163
+ # The location of ri data installed into the site dir.
164
+ #
165
+ # Historically this was available for documentation installed by ruby
166
+ # libraries predating RubyGems. It is unlikely to contain any content for
167
+ # modern ruby installations.
168
+
169
+ def self.site_dir
170
+ File.join BASE, 'site'
171
+ end
172
+
173
+ ##
174
+ # The location of the built-in ri data.
175
+ #
176
+ # This data is built automatically when `make` is run when ruby is
177
+ # installed. If you did not install ruby by hand you may need to install
178
+ # the documentation yourself. Please consult the documentation for your
179
+ # package manager or ruby installer for details. You can also use the
180
+ # rdoc-data gem to install system ri data for common versions of ruby.
181
+
182
+ def self.system_dir
183
+ File.join BASE, 'system'
184
+ end
185
+
127
186
  end
128
187
 
@@ -1,357 +1,6 @@
1
- require 'fileutils'
1
+ module RDoc::RI
2
2
 
3
- ##
4
- # A set of ri data.
5
- #
6
- # The store manages reading and writing ri data for a project (gem, path,
7
- # etc.) and maintains a cache of methods, classes and ancestors in the
8
- # store.
9
- #
10
- # The store maintains a #cache of its contents for faster lookup. After
11
- # adding items to the store it must be flushed using #save_cache. The cache
12
- # contains the following structures:
13
- #
14
- # @cache = {
15
- # :class_methods => {}, # class name => class methods
16
- # :instance_methods => {}, # class name => instance methods
17
- # :attributes => {}, # class name => attributes
18
- # :modules => [], # classes and modules in this store
19
- # :ancestors => {}, # class name => ancestor names
20
- # }
21
- #--
22
- # TODO need to store the list of files and prune classes
23
-
24
- class RDoc::RI::Store
25
-
26
- ##
27
- # If true this Store will not write any files
28
-
29
- attr_accessor :dry_run
30
-
31
- ##
32
- # Path this store reads or writes
33
-
34
- attr_accessor :path
35
-
36
- ##
37
- # Type of ri datastore this was loaded from. See RDoc::RI::Driver,
38
- # RDoc::RI::Paths.
39
-
40
- attr_accessor :type
41
-
42
- ##
43
- # The contents of the Store
44
-
45
- attr_reader :cache
46
-
47
- ##
48
- # The encoding of the contents in the Store
49
-
50
- attr_accessor :encoding
51
-
52
- ##
53
- # Creates a new Store of +type+ that will load or save to +path+
54
-
55
- def initialize path, type = nil
56
- @dry_run = false
57
- @type = type
58
- @path = path
59
- @encoding = nil
60
-
61
- @cache = {
62
- :ancestors => {},
63
- :attributes => {},
64
- :class_methods => {},
65
- :encoding => @encoding,
66
- :instance_methods => {},
67
- :modules => [],
68
- }
69
- end
70
-
71
- ##
72
- # Ancestors cache accessor. Maps a klass name to an Array of its ancestors
73
- # in this store. If Foo in this store inherits from Object, Kernel won't be
74
- # listed (it will be included from ruby's ri store).
75
-
76
- def ancestors
77
- @cache[:ancestors]
78
- end
79
-
80
- ##
81
- # Attributes cache accessor. Maps a class to an Array of its attributes.
82
-
83
- def attributes
84
- @cache[:attributes]
85
- end
86
-
87
- ##
88
- # Path to the cache file
89
-
90
- def cache_path
91
- File.join @path, 'cache.ri'
92
- end
93
-
94
- ##
95
- # Path to the ri data for +klass_name+
96
-
97
- def class_file klass_name
98
- name = klass_name.split('::').last
99
- File.join class_path(klass_name), "cdesc-#{name}.ri"
100
- end
101
-
102
- ##
103
- # Class methods cache accessor. Maps a class to an Array of its class
104
- # methods (not full name).
105
-
106
- def class_methods
107
- @cache[:class_methods]
108
- end
109
-
110
- ##
111
- # Path where data for +klass_name+ will be stored (methods or class data)
112
-
113
- def class_path klass_name
114
- File.join @path, *klass_name.split('::')
115
- end
116
-
117
- ##
118
- # Removes empty items and ensures item in each collection are unique and
119
- # sorted
120
-
121
- def clean_cache_collection collection # :nodoc:
122
- collection.each do |name, item|
123
- if item.empty? then
124
- collection.delete name
125
- else
126
- # HACK mongrel-1.1.5 documents its files twice
127
- item.uniq!
128
- item.sort!
129
- end
130
- end
131
- end
132
-
133
- ##
134
- # Friendly rendition of #path
135
-
136
- def friendly_path
137
- case type
138
- when :gem then
139
- sep = Regexp.union(*['/', File::ALT_SEPARATOR].compact)
140
- @path =~ /#{sep}doc#{sep}(.*?)#{sep}ri$/
141
- "gem #{$1}"
142
- when :home then '~/.ri'
143
- when :site then 'ruby site'
144
- when :system then 'ruby core'
145
- else @path
146
- end
147
- end
148
-
149
- def inspect # :nodoc:
150
- "#<%s:0x%x %s %p>" % [self.class, object_id, @path, modules.sort]
151
- end
152
-
153
- ##
154
- # Instance methods cache accessor. Maps a class to an Array of its
155
- # instance methods (not full name).
156
-
157
- def instance_methods
158
- @cache[:instance_methods]
159
- end
160
-
161
- ##
162
- # Loads cache file for this store
163
-
164
- def load_cache
165
- #orig_enc = @encoding
166
-
167
- open cache_path, 'rb' do |io|
168
- @cache = Marshal.load io.read
169
- end
170
-
171
- load_enc = @cache[:encoding]
172
-
173
- # TODO this feature will be time-consuming to add:
174
- # a) Encodings may be incompatible but transcodeable
175
- # b) Need to warn in the appropriate spots, wherever they may be
176
- # c) Need to handle cross-cache differences in encodings
177
- # d) Need to warn when generating into a cache with diffent encodings
178
- #
179
- #if orig_enc and load_enc != orig_enc then
180
- # warn "Cached encoding #{load_enc} is incompatible with #{orig_enc}\n" \
181
- # "from #{path}/cache.ri" unless
182
- # Encoding.compatible? orig_enc, load_enc
183
- #end
184
-
185
- @encoding = load_enc unless @encoding
186
-
187
- @cache
188
- rescue Errno::ENOENT
189
- end
190
-
191
- ##
192
- # Loads ri data for +klass_name+
193
-
194
- def load_class klass_name
195
- open class_file(klass_name), 'rb' do |io|
196
- Marshal.load io.read
197
- end
198
- end
199
-
200
- ##
201
- # Loads ri data for +method_name+ in +klass_name+
202
-
203
- def load_method klass_name, method_name
204
- open method_file(klass_name, method_name), 'rb' do |io|
205
- Marshal.load io.read
206
- end
207
- end
208
-
209
- ##
210
- # Path to the ri data for +method_name+ in +klass_name+
211
-
212
- def method_file klass_name, method_name
213
- method_name = method_name.split('::').last
214
- method_name =~ /#(.*)/
215
- method_type = $1 ? 'i' : 'c'
216
- method_name = $1 if $1
217
-
218
- method_name = if ''.respond_to? :ord then
219
- method_name.gsub(/\W/) { "%%%02x" % $&[0].ord }
220
- else
221
- method_name.gsub(/\W/) { "%%%02x" % $&[0] }
222
- end
223
-
224
- File.join class_path(klass_name), "#{method_name}-#{method_type}.ri"
225
- end
226
-
227
- ##
228
- # Modules cache accessor. An Array of all the modules (and classes) in the
229
- # store.
230
-
231
- def modules
232
- @cache[:modules]
233
- end
234
-
235
- ##
236
- # Writes the cache file for this store
237
-
238
- def save_cache
239
- clean_cache_collection @cache[:ancestors]
240
- clean_cache_collection @cache[:attributes]
241
- clean_cache_collection @cache[:class_methods]
242
- clean_cache_collection @cache[:instance_methods]
243
-
244
- @cache[:modules].uniq!
245
- @cache[:modules].sort!
246
- @cache[:encoding] = @encoding # this gets set twice due to assert_cache
247
-
248
- return if @dry_run
249
-
250
- marshal = Marshal.dump @cache
251
-
252
- open cache_path, 'wb' do |io|
253
- io.write marshal
254
- end
255
- end
256
-
257
- ##
258
- # Writes the ri data for +klass+
259
-
260
- def save_class klass
261
- full_name = klass.full_name
262
-
263
- FileUtils.mkdir_p class_path(full_name) unless @dry_run
264
-
265
- @cache[:modules] << full_name
266
-
267
- path = class_file full_name
268
-
269
- begin
270
- disk_klass = load_class full_name
271
-
272
- klass = disk_klass.merge klass
273
- rescue Errno::ENOENT
274
- end
275
-
276
- # BasicObject has no ancestors
277
- ancestors = klass.ancestors.compact.map do |ancestor|
278
- # HACK for classes we don't know about (class X < RuntimeError)
279
- String === ancestor ? ancestor : ancestor.full_name
280
- end
281
-
282
- @cache[:ancestors][full_name] ||= []
283
- @cache[:ancestors][full_name].push(*ancestors)
284
-
285
- attributes = klass.attributes.map do |attribute|
286
- "#{attribute.definition} #{attribute.name}"
287
- end
288
-
289
- unless attributes.empty? then
290
- @cache[:attributes][full_name] ||= []
291
- @cache[:attributes][full_name].push(*attributes)
292
- end
293
-
294
- to_delete = []
295
-
296
- unless klass.method_list.empty? then
297
- @cache[:class_methods][full_name] ||= []
298
- @cache[:instance_methods][full_name] ||= []
299
-
300
- class_methods, instance_methods =
301
- klass.method_list.partition { |meth| meth.singleton }
302
-
303
- class_methods = class_methods. map { |method| method.name }
304
- instance_methods = instance_methods.map { |method| method.name }
305
-
306
- old = @cache[:class_methods][full_name] - class_methods
307
- to_delete.concat old.map { |method|
308
- method_file full_name, "#{full_name}::#{method}"
309
- }
310
-
311
- old = @cache[:instance_methods][full_name] - instance_methods
312
- to_delete.concat old.map { |method|
313
- method_file full_name, "#{full_name}##{method}"
314
- }
315
-
316
- @cache[:class_methods][full_name] = class_methods
317
- @cache[:instance_methods][full_name] = instance_methods
318
- end
319
-
320
- return if @dry_run
321
-
322
- FileUtils.rm_f to_delete
323
-
324
- marshal = Marshal.dump klass
325
-
326
- open path, 'wb' do |io|
327
- io.write marshal
328
- end
329
- end
330
-
331
- ##
332
- # Writes the ri data for +method+ on +klass+
333
-
334
- def save_method klass, method
335
- full_name = klass.full_name
336
-
337
- FileUtils.mkdir_p class_path(full_name) unless @dry_run
338
-
339
- cache = if method.singleton then
340
- @cache[:class_methods]
341
- else
342
- @cache[:instance_methods]
343
- end
344
- cache[full_name] ||= []
345
- cache[full_name] << method.name
346
-
347
- return if @dry_run
348
-
349
- marshal = Marshal.dump method
350
-
351
- open method_file(full_name, method.full_name), 'wb' do |io|
352
- io.write marshal
353
- end
354
- end
3
+ Store = RDoc::Store # :nodoc:
355
4
 
356
5
  end
357
6