rdoc 8.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -3
  3. data/RI.md +75 -75
  4. data/exe/rdoc +2 -2
  5. data/lib/rdoc/code_object/alias.rb +71 -69
  6. data/lib/rdoc/code_object/any_method.rb +305 -303
  7. data/lib/rdoc/code_object/attr.rb +150 -148
  8. data/lib/rdoc/code_object/class_module.rb +798 -792
  9. data/lib/rdoc/code_object/constant.rb +175 -173
  10. data/lib/rdoc/code_object/context/section.rb +142 -138
  11. data/lib/rdoc/code_object/context.rb +926 -958
  12. data/lib/rdoc/code_object/extend.rb +7 -5
  13. data/lib/rdoc/code_object/include.rb +7 -5
  14. data/lib/rdoc/code_object/method_attr.rb +326 -319
  15. data/lib/rdoc/code_object/mixin.rb +97 -95
  16. data/lib/rdoc/code_object/normal_class.rb +77 -78
  17. data/lib/rdoc/code_object/normal_module.rb +61 -59
  18. data/lib/rdoc/code_object/require.rb +23 -39
  19. data/lib/rdoc/code_object/single_class.rb +21 -19
  20. data/lib/rdoc/code_object/top_level.rb +212 -219
  21. data/lib/rdoc/code_object.rb +305 -303
  22. data/lib/rdoc/comment.rb +275 -273
  23. data/lib/rdoc/cross_reference.rb +192 -190
  24. data/lib/rdoc/encoding.rb +105 -103
  25. data/lib/rdoc/erb_partial.rb +13 -11
  26. data/lib/rdoc/erbio.rb +29 -27
  27. data/lib/rdoc/generator/aliki.rb +161 -153
  28. data/lib/rdoc/generator/darkfish.rb +645 -635
  29. data/lib/rdoc/generator/json_index.rb +233 -229
  30. data/lib/rdoc/generator/markup.rb +164 -146
  31. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  32. data/lib/rdoc/generator/pot/po.rb +52 -51
  33. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  34. data/lib/rdoc/generator/pot.rb +85 -81
  35. data/lib/rdoc/generator/ri.rb +23 -19
  36. data/lib/rdoc/generator/template/aliki/DESIGN.md +6 -4
  37. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  38. data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
  39. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  40. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  41. data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
  42. data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  44. data/lib/rdoc/generator.rb +48 -46
  45. data/lib/rdoc/i18n/locale.rb +99 -95
  46. data/lib/rdoc/i18n/text.rb +109 -105
  47. data/lib/rdoc/i18n.rb +7 -5
  48. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  49. data/lib/rdoc/markdown.kpeg +15 -11
  50. data/lib/rdoc/markdown.rb +40 -47
  51. data/lib/rdoc/markup/block_quote.rb +12 -8
  52. data/lib/rdoc/markup/document.rb +127 -123
  53. data/lib/rdoc/markup/formatter.rb +219 -215
  54. data/lib/rdoc/markup/include.rb +33 -29
  55. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  56. data/lib/rdoc/markup/inline_parser.rb +281 -277
  57. data/lib/rdoc/markup/list.rb +80 -88
  58. data/lib/rdoc/markup/list_item.rb +73 -85
  59. data/lib/rdoc/markup/paragraph.rb +23 -19
  60. data/lib/rdoc/markup/parser.rb +501 -497
  61. data/lib/rdoc/markup/pre_process.rb +283 -279
  62. data/lib/rdoc/markup/raw.rb +2 -2
  63. data/lib/rdoc/markup/rule.rb +16 -12
  64. data/lib/rdoc/markup/to_ansi.rb +143 -139
  65. data/lib/rdoc/markup/to_bs.rb +72 -68
  66. data/lib/rdoc/markup/to_html.rb +594 -565
  67. data/lib/rdoc/markup/to_html_crossref.rb +234 -230
  68. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  69. data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
  70. data/lib/rdoc/markup/to_label.rb +63 -59
  71. data/lib/rdoc/markup/to_markdown.rb +212 -208
  72. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  73. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  74. data/lib/rdoc/markup/to_test.rb +60 -56
  75. data/lib/rdoc/markup/to_tt_only.rb +84 -80
  76. data/lib/rdoc/markup/verbatim.rb +62 -58
  77. data/lib/rdoc/markup.rb +198 -196
  78. data/lib/rdoc/options.rb +1063 -1061
  79. data/lib/rdoc/parser/c.rb +1039 -1037
  80. data/lib/rdoc/parser/changelog.rb +319 -315
  81. data/lib/rdoc/parser/markdown.rb +17 -13
  82. data/lib/rdoc/parser/rbs.rb +239 -235
  83. data/lib/rdoc/parser/rd.rb +17 -13
  84. data/lib/rdoc/parser/ruby.rb +1245 -1124
  85. data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
  86. data/lib/rdoc/parser/simple.rb +31 -27
  87. data/lib/rdoc/parser/text.rb +12 -8
  88. data/lib/rdoc/parser.rb +228 -220
  89. data/lib/rdoc/rbs_helper.rb +1 -1
  90. data/lib/rdoc/rd/inline.rb +57 -53
  91. data/lib/rdoc/rd.rb +90 -88
  92. data/lib/rdoc/rdoc.rb +500 -491
  93. data/lib/rdoc/ri/driver.rb +1140 -1135
  94. data/lib/rdoc/ri/formatter.rb +7 -3
  95. data/lib/rdoc/ri/paths.rb +140 -136
  96. data/lib/rdoc/ri/servlet.rb +354 -350
  97. data/lib/rdoc/ri/store.rb +4 -2
  98. data/lib/rdoc/ri/task.rb +55 -51
  99. data/lib/rdoc/ri.rb +14 -12
  100. data/lib/rdoc/rubygems_hook.rb +183 -181
  101. data/lib/rdoc/server.rb +349 -347
  102. data/lib/rdoc/stats/normal.rb +46 -42
  103. data/lib/rdoc/stats/quiet.rb +39 -35
  104. data/lib/rdoc/stats/verbose.rb +35 -31
  105. data/lib/rdoc/stats.rb +365 -363
  106. data/lib/rdoc/store.rb +888 -902
  107. data/lib/rdoc/task.rb +260 -256
  108. data/lib/rdoc/text.rb +135 -133
  109. data/lib/rdoc/token_stream.rb +101 -93
  110. data/lib/rdoc/tom_doc.rb +203 -201
  111. data/lib/rdoc/version.rb +1 -1
  112. metadata +4 -5
  113. data/lib/rdoc/markdown/literals.kpeg +0 -21
  114. data/lib/rdoc/markdown/literals.rb +0 -454
@@ -1,1238 +1,1206 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # A Context is something that can hold modules, classes, methods, attributes,
4
- # aliases, requires, and includes. Classes, modules, and files are all
5
- # Contexts.
6
-
7
- class RDoc::Context < RDoc::CodeObject
8
-
9
- include Comparable
10
-
2
+ module RDoc
11
3
  ##
12
- # Types of methods
4
+ # A Context is something that can hold modules, classes, methods, attributes,
5
+ # aliases, requires, and includes. Classes, modules, and files are all
6
+ # Contexts.
13
7
 
14
- TYPES = %w[class instance]
8
+ class Context < CodeObject
15
9
 
16
- ##
17
- # If a context has these titles it will be sorted in this order.
10
+ include Comparable
18
11
 
19
- TOMDOC_TITLES = [nil, 'Public', 'Internal', 'Deprecated'] # :nodoc:
20
- TOMDOC_TITLES_SORT = TOMDOC_TITLES.sort_by { |title| title.to_s } # :nodoc:
12
+ ##
13
+ # Types of methods
21
14
 
22
- ##
23
- # Class/module aliases
15
+ TYPES = %w[class instance]
24
16
 
25
- attr_reader :aliases
17
+ ##
18
+ # If a context has these titles it will be sorted in this order.
26
19
 
27
- ##
28
- # All attr* methods
20
+ TOMDOC_TITLES = [nil, 'Public', 'Internal', 'Deprecated'] # :nodoc:
21
+ TOMDOC_TITLES_SORT = TOMDOC_TITLES.sort_by { |title| title.to_s } # :nodoc:
29
22
 
30
- attr_reader :attributes
23
+ ##
24
+ # Class/module aliases
31
25
 
32
- ##
33
- # Block params to be used in the next MethodAttr parsed under this context
26
+ attr_reader :aliases
34
27
 
35
- attr_accessor :block_params
28
+ ##
29
+ # All attr* methods
36
30
 
37
- ##
38
- # Constants defined
31
+ attr_reader :attributes
39
32
 
40
- attr_reader :constants
33
+ ##
34
+ # Block params to be used in the next MethodAttr parsed under this context
41
35
 
42
- ##
43
- # Sets the current documentation section of documentation
36
+ attr_accessor :block_params
44
37
 
45
- attr_writer :current_section
38
+ ##
39
+ # Constants defined
46
40
 
47
- ##
48
- # Files this context is found in
41
+ attr_reader :constants
49
42
 
50
- attr_reader :in_files
43
+ ##
44
+ # Sets the current documentation section of documentation
51
45
 
52
- ##
53
- # Modules this context includes
46
+ attr_writer :current_section
54
47
 
55
- attr_reader :includes
48
+ ##
49
+ # Files this context is found in
56
50
 
57
- ##
58
- # Modules this context is extended with
59
-
60
- attr_reader :extends
61
-
62
- ##
63
- # Methods defined in this context
64
-
65
- attr_reader :method_list
51
+ attr_reader :in_files
66
52
 
67
- ##
68
- # Name of this class excluding namespace. See also full_name
53
+ ##
54
+ # Modules this context includes
69
55
 
70
- attr_reader :name
56
+ attr_reader :includes
71
57
 
72
- ##
73
- # Files this context requires
58
+ ##
59
+ # Modules this context is extended with
74
60
 
75
- attr_reader :requires
61
+ attr_reader :extends
76
62
 
77
- ##
78
- # Use this section for the next method, attribute or constant added.
63
+ ##
64
+ # Methods defined in this context
79
65
 
80
- attr_accessor :temporary_section
66
+ attr_reader :method_list
81
67
 
82
- ##
83
- # Hash <tt>old_name => [aliases]</tt>, for aliases
84
- # that haven't (yet) been resolved to a method/attribute.
85
- # (Not to be confused with the aliases of the context.)
68
+ ##
69
+ # Name of this class excluding namespace. See also full_name
86
70
 
87
- attr_accessor :unmatched_alias_lists
71
+ attr_reader :name
88
72
 
89
- ##
90
- # Aliases that could not be resolved.
73
+ ##
74
+ # Files this context requires
91
75
 
92
- attr_reader :external_aliases
76
+ attr_reader :requires
93
77
 
94
- ##
95
- # Current visibility of this context
78
+ ##
79
+ # Use this section for the next method, attribute or constant added.
96
80
 
97
- attr_accessor :visibility
81
+ attr_accessor :temporary_section
98
82
 
99
- ##
100
- # Current visibility of this line
83
+ ##
84
+ # Hash <tt>old_name => [aliases]</tt>, for aliases
85
+ # that haven't (yet) been resolved to a method/attribute.
86
+ # (Not to be confused with the aliases of the context.)
101
87
 
102
- attr_writer :current_line_visibility
88
+ attr_accessor :unmatched_alias_lists
103
89
 
104
- ##
105
- # Hash of registered methods. Attributes are also registered here,
106
- # twice if they are RW.
90
+ ##
91
+ # Aliases that could not be resolved.
107
92
 
108
- attr_reader :methods_hash
93
+ attr_reader :external_aliases
109
94
 
110
- ##
111
- # Params to be used in the next MethodAttr parsed under this context
95
+ ##
96
+ # Hash of registered methods. Attributes are also registered here,
97
+ # twice if they are RW.
112
98
 
113
- attr_accessor :params
99
+ attr_reader :methods_hash
114
100
 
115
- ##
116
- # Hash of registered constants.
101
+ ##
102
+ # Params to be used in the next MethodAttr parsed under this context
117
103
 
118
- attr_reader :constants_hash
104
+ attr_accessor :params
119
105
 
120
- ##
121
- # Creates an unnamed empty context with public current visibility
106
+ ##
107
+ # Hash of registered constants.
122
108
 
123
- def initialize
124
- super
109
+ attr_reader :constants_hash
125
110
 
126
- @in_files = []
111
+ ##
112
+ # Creates an unnamed empty context
127
113
 
128
- @name ||= "unknown"
129
- @parent = nil
130
- @visibility = :public
114
+ def initialize
115
+ super
131
116
 
132
- @current_section = Section.new self, nil, nil
133
- @sections = { nil => @current_section }
134
- @temporary_section = nil
117
+ @in_files = []
135
118
 
136
- @classes = {}
137
- @modules = {}
119
+ @name ||= "unknown"
120
+ @parent = nil
121
+ @current_section = Section.new self, nil, nil
122
+ @sections = { nil => @current_section }
123
+ @temporary_section = nil
138
124
 
139
- initialize_methods_etc
140
- end
125
+ @classes = {}
126
+ @modules = {}
141
127
 
142
- ##
143
- # Sets the defaults for methods and so-forth
128
+ initialize_methods_etc
129
+ end
144
130
 
145
- def initialize_methods_etc
146
- @method_list = []
147
- @attributes = []
148
- @aliases = []
149
- @requires = []
150
- @includes = []
151
- @extends = []
152
- @constants = []
153
- @external_aliases = []
154
- @current_line_visibility = nil
131
+ ##
132
+ # Sets the defaults for methods and so-forth
155
133
 
156
- # This Hash maps a method name to a list of unmatched aliases (aliases of
157
- # a method not yet encountered).
158
- @unmatched_alias_lists = {}
134
+ def initialize_methods_etc
135
+ @method_list = []
136
+ @attributes = []
137
+ @aliases = []
138
+ @requires = []
139
+ @includes = []
140
+ @extends = []
141
+ @constants = []
142
+ @external_aliases = []
143
+ # This Hash maps a method name to a list of unmatched aliases (aliases of
144
+ # a method not yet encountered).
145
+ @unmatched_alias_lists = {}
159
146
 
160
- @methods_hash = {}
161
- @constants_hash = {}
147
+ @methods_hash = {}
148
+ @constants_hash = {}
162
149
 
163
- @params = nil
150
+ @params = nil
164
151
 
165
- @store ||= nil
166
- end
152
+ @store ||= nil
153
+ end
167
154
 
168
- ##
169
- # Contexts are sorted by full_name
155
+ ##
156
+ # Contexts are sorted by full_name
170
157
 
171
- def <=>(other)
172
- return nil unless RDoc::CodeObject === other
158
+ def <=>(other)
159
+ return nil unless CodeObject === other
173
160
 
174
- full_name <=> other.full_name
175
- end
161
+ full_name <=> other.full_name
162
+ end
176
163
 
177
- ##
178
- # Adds an item of type +klass+ with the given +name+ and +comment+ to the
179
- # context.
180
- #
181
- # Currently only RDoc::Extend and RDoc::Include are supported.
182
-
183
- def add(klass, name, comment)
184
- if RDoc::Extend == klass then
185
- ext = RDoc::Extend.new name, comment
186
- add_extend ext
187
- elsif RDoc::Include == klass then
188
- incl = RDoc::Include.new name, comment
189
- add_include incl
190
- else
191
- raise NotImplementedError, "adding a #{klass} is not implemented"
164
+ ##
165
+ # Adds an item of type +klass+ with the given +name+ and +comment+ to the
166
+ # context.
167
+ #
168
+ # Currently only RDoc::Extend and RDoc::Include are supported.
169
+
170
+ def add(klass, name, comment)
171
+ if Extend == klass
172
+ ext = Extend.new name, comment
173
+ add_extend ext
174
+ elsif Include == klass
175
+ incl = Include.new name, comment
176
+ add_include incl
177
+ else
178
+ raise NotImplementedError, "adding a #{klass} is not implemented"
179
+ end
192
180
  end
193
- end
194
181
 
195
- ##
196
- # Adds +an_alias+ that is automatically resolved
182
+ ##
183
+ # Adds +an_alias+ that is automatically resolved
197
184
 
198
- def add_alias(an_alias)
199
- return an_alias unless @document_self
185
+ def add_alias(an_alias)
186
+ return an_alias unless @document_self
200
187
 
201
- method_attr = find_method(an_alias.old_name, an_alias.singleton) ||
202
- find_attribute(an_alias.old_name, an_alias.singleton)
188
+ method_attr = find_method(an_alias.old_name, an_alias.singleton) ||
189
+ find_attribute(an_alias.old_name, an_alias.singleton)
203
190
 
204
- if method_attr then
205
- method_attr.add_alias an_alias, self
206
- else
207
- add_to @external_aliases, an_alias
208
- unmatched_alias_list =
209
- @unmatched_alias_lists[an_alias.pretty_old_name] ||= []
210
- unmatched_alias_list.push an_alias
211
- end
191
+ if method_attr
192
+ method_attr.add_alias an_alias, self
193
+ else
194
+ add_to @external_aliases, an_alias
195
+ unmatched_alias_list =
196
+ @unmatched_alias_lists[an_alias.pretty_old_name] ||= []
197
+ unmatched_alias_list.push an_alias
198
+ end
212
199
 
213
- an_alias
214
- end
200
+ an_alias
201
+ end
215
202
 
216
- ##
217
- # Adds +attribute+ if not already there. If it is (as method(s) or attribute),
218
- # updates the comment if it was empty.
219
- #
220
- # The attribute is registered only if it defines a new method.
221
- # For instance, <tt>attr_reader :foo</tt> will not be registered
222
- # if method +foo+ exists, but <tt>attr_accessor :foo</tt> will be registered
223
- # if method +foo+ exists, but <tt>foo=</tt> does not.
203
+ ##
204
+ # Adds +attribute+ if not already there. If it is (as method(s) or attribute),
205
+ # updates the comment if it was empty.
206
+ #
207
+ # The attribute is registered only if it defines a new method.
208
+ # For instance, <tt>attr_reader :foo</tt> will not be registered
209
+ # if method +foo+ exists, but <tt>attr_accessor :foo</tt> will be registered
210
+ # if method +foo+ exists, but <tt>foo=</tt> does not.
224
211
 
225
- def add_attribute(attribute)
226
- return attribute unless @document_self
212
+ def add_attribute(attribute)
213
+ return attribute unless @document_self
227
214
 
228
- # mainly to check for redefinition of an attribute as a method
229
- # TODO find a policy for 'attr_reader :foo' + 'def foo=()'
230
- register = false
215
+ # mainly to check for redefinition of an attribute as a method
216
+ # TODO find a policy for 'attr_reader :foo' + 'def foo=()'
217
+ register = false
231
218
 
232
- key = nil
219
+ key = nil
233
220
 
234
- if attribute.rw.index 'R' then
235
- key = attribute.pretty_name
236
- known = @methods_hash[key]
221
+ if attribute.rw.index 'R'
222
+ key = attribute.pretty_name
223
+ known = @methods_hash[key]
237
224
 
238
- if known then
239
- known.comment = attribute.comment if known.comment.empty?
240
- elsif registered = @methods_hash[attribute.pretty_name + '='] and
241
- RDoc::Attr === registered then
242
- registered.rw = 'RW'
243
- else
244
- @methods_hash[key] = attribute
245
- register = true
225
+ if known
226
+ known.comment = attribute.comment if known.comment.empty?
227
+ elsif registered = @methods_hash[attribute.pretty_name + '='] and
228
+ Attr === registered
229
+ registered.rw = 'RW'
230
+ else
231
+ @methods_hash[key] = attribute
232
+ register = true
233
+ end
246
234
  end
247
- end
248
235
 
249
- if attribute.rw.index 'W' then
250
- key = attribute.pretty_name + '='
251
- known = @methods_hash[key]
236
+ if attribute.rw.index 'W'
237
+ key = attribute.pretty_name + '='
238
+ known = @methods_hash[key]
252
239
 
253
- if known then
254
- known.comment = attribute.comment if known.comment.empty?
255
- elsif registered = @methods_hash[attribute.pretty_name] and
256
- RDoc::Attr === registered then
257
- registered.rw = 'RW'
258
- else
259
- @methods_hash[key] = attribute
260
- register = true
240
+ if known
241
+ known.comment = attribute.comment if known.comment.empty?
242
+ elsif registered = @methods_hash[attribute.pretty_name] and
243
+ Attr === registered
244
+ registered.rw = 'RW'
245
+ else
246
+ @methods_hash[key] = attribute
247
+ register = true
248
+ end
261
249
  end
262
- end
263
250
 
264
- if register then
265
- attribute.visibility = @visibility
266
- add_to @attributes, attribute
267
- resolve_aliases attribute
268
- end
251
+ if register
252
+ add_to @attributes, attribute
253
+ resolve_aliases attribute
254
+ end
269
255
 
270
- attribute
271
- end
256
+ attribute
257
+ end
272
258
 
273
- ##
274
- # Adds a class named +given_name+ with +superclass+.
275
- #
276
- # Both +given_name+ and +superclass+ may contain '::', and are
277
- # interpreted relative to the +self+ context. This allows handling correctly
278
- # examples like these:
279
- # class RDoc::Gauntlet < Gauntlet
280
- # module Mod
281
- # class Object # implies < ::Object
282
- # class SubObject < Object # this is _not_ ::Object
283
- #
284
- # Given <tt>class Container::Item</tt> RDoc assumes +Container+ is a module
285
- # unless it later sees <tt>class Container</tt>. +add_class+ automatically
286
- # upgrades +given_name+ to a class in this case.
287
-
288
- def add_class(class_type, given_name, superclass = '::Object')
289
- # superclass +nil+ is passed by the C parser in the following cases:
290
- # - registering Object in 1.8 (correct)
291
- # - registering BasicObject in 1.9 (correct)
292
- # - registering RubyVM in 1.9 in iseq.c (incorrect: < Object in vm.c)
259
+ ##
260
+ # Adds a class named +given_name+ with +superclass+.
293
261
  #
294
- # If we later find a superclass for a registered class with a nil
295
- # superclass, we must honor it.
296
-
297
- # find the name & enclosing context
298
- if given_name =~ /^:+(\w+)$/ then
299
- full_name = $1
300
- enclosing = top_level
301
- name = full_name.split(/:+/).last
302
- else
303
- full_name = child_name given_name
304
-
305
- if full_name =~ /^(.+)::(\w+)$/ then
306
- name = $2
307
- ename = $1
308
- enclosing = @store.classes_hash[ename] || @store.modules_hash[ename]
309
- # HACK: crashes in actionpack/lib/action_view/helpers/form_helper.rb (metaprogramming)
310
- unless enclosing then
311
- # try the given name at top level (will work for the above example)
312
- enclosing = @store.classes_hash[given_name] ||
313
- @store.modules_hash[given_name]
314
- return enclosing if enclosing
315
- # not found: create the parent(s)
316
- enclosing = find_or_create_namespace_path ename
317
- end
262
+ # Both +given_name+ and +superclass+ may contain '::', and are
263
+ # interpreted relative to the +self+ context. This allows handling correctly
264
+ # examples like these:
265
+ # class RDoc::Gauntlet < Gauntlet
266
+ # module Mod
267
+ # class Object # implies < ::Object
268
+ # class SubObject < Object # this is _not_ ::Object
269
+ #
270
+ # Given <tt>class Container::Item</tt> RDoc assumes +Container+ is a module
271
+ # unless it later sees <tt>class Container</tt>. +add_class+ automatically
272
+ # upgrades +given_name+ to a class in this case.
273
+
274
+ def add_class(class_type, given_name, superclass = '::Object')
275
+ # superclass +nil+ is passed by the C parser in the following cases:
276
+ # - registering Object in 1.8 (correct)
277
+ # - registering BasicObject in 1.9 (correct)
278
+ # - registering RubyVM in 1.9 in iseq.c (incorrect: < Object in vm.c)
279
+ #
280
+ # If we later find a superclass for a registered class with a nil
281
+ # superclass, we must honor it.
282
+
283
+ # find the name & enclosing context
284
+ if given_name =~ /^:+(\w+)$/
285
+ full_name = $1
286
+ enclosing = top_level
287
+ name = full_name.split(/:+/).last
318
288
  else
319
- name = full_name
320
- enclosing = self
289
+ full_name = child_name given_name
290
+
291
+ if full_name =~ /^(.+)::(\w+)$/
292
+ name = $2
293
+ ename = $1
294
+ enclosing = @store.classes_hash[ename] || @store.modules_hash[ename]
295
+ # HACK: crashes in actionpack/lib/action_view/helpers/form_helper.rb (metaprogramming)
296
+ unless enclosing
297
+ # try the given name at top level (will work for the above example)
298
+ enclosing = @store.classes_hash[given_name] ||
299
+ @store.modules_hash[given_name]
300
+ return enclosing if enclosing
301
+ # not found: create the parent(s)
302
+ enclosing = find_or_create_namespace_path ename
303
+ end
304
+ else
305
+ name = full_name
306
+ enclosing = self
307
+ end
321
308
  end
322
- end
323
309
 
324
- # fix up superclass
325
- if full_name == 'BasicObject' then
326
- superclass = nil
327
- elsif full_name == 'Object' then
328
- superclass = '::BasicObject'
329
- end
310
+ # fix up superclass
311
+ if full_name == 'BasicObject'
312
+ superclass = nil
313
+ elsif full_name == 'Object'
314
+ superclass = '::BasicObject'
315
+ end
330
316
 
331
- # find the superclass full name
332
- if superclass then
333
- if superclass =~ /^:+/ then
334
- superclass = $' #'
335
- else
336
- if superclass =~ /^(\w+):+(.+)$/ then
337
- suffix = $2
338
- mod = find_module_named($1)
339
- superclass = mod.full_name + '::' + suffix if mod
317
+ # find the superclass full name
318
+ if superclass
319
+ if superclass =~ /^:+/
320
+ superclass = $' #'
340
321
  else
341
- mod = find_module_named(superclass)
342
- superclass = mod.full_name if mod
322
+ if superclass =~ /^(\w+):+(.+)$/
323
+ suffix = $2
324
+ mod = find_module_named($1)
325
+ superclass = mod.full_name + '::' + suffix if mod
326
+ else
327
+ mod = find_module_named(superclass)
328
+ superclass = mod.full_name if mod
329
+ end
343
330
  end
344
- end
345
331
 
346
- # did we believe it was a module?
347
- mod = @store.modules_hash.delete superclass
332
+ # did we believe it was a module?
333
+ mod = @store.modules_hash.delete superclass
348
334
 
349
- upgrade_to_class mod, RDoc::NormalClass, mod.parent if mod
335
+ upgrade_to_class mod, NormalClass, mod.parent if mod
350
336
 
351
- # e.g., Object < Object
352
- superclass = nil if superclass == full_name
353
- end
337
+ # e.g., Object < Object
338
+ superclass = nil if superclass == full_name
339
+ end
354
340
 
355
- klass = @store.classes_hash[full_name]
341
+ klass = @store.classes_hash[full_name]
356
342
 
357
- if klass then
358
- # if TopLevel, it may not be registered in the classes:
359
- enclosing.classes_hash[name] = klass
343
+ if klass
344
+ # if TopLevel, it may not be registered in the classes:
345
+ enclosing.classes_hash[name] = klass
360
346
 
361
- # update the superclass if needed
362
- if superclass then
363
- existing = klass.superclass
364
- existing = existing.full_name unless existing.is_a?(String) if existing
365
- if existing.nil? ||
366
- (existing == 'Object' && superclass != 'Object') then
367
- klass.superclass = superclass
347
+ # update the superclass if needed
348
+ if superclass
349
+ existing = klass.superclass
350
+ existing = existing.full_name unless existing.is_a?(String) if existing
351
+ if existing.nil? ||
352
+ (existing == 'Object' && superclass != 'Object')
353
+ klass.superclass = superclass
354
+ end
368
355
  end
369
- end
370
- else
371
- # this is a new class
372
- mod = @store.modules_hash.delete full_name
356
+ else
357
+ # this is a new class
358
+ mod = @store.modules_hash.delete full_name
373
359
 
374
- if mod then
375
- klass = upgrade_to_class mod, RDoc::NormalClass, enclosing
360
+ if mod
361
+ klass = upgrade_to_class mod, NormalClass, enclosing
376
362
 
377
- klass.superclass = superclass unless superclass.nil?
378
- else
379
- klass = class_type.new name, superclass
363
+ klass.superclass = superclass unless superclass.nil?
364
+ else
365
+ klass = class_type.new name, superclass
380
366
 
381
- enclosing.add_class_or_module(klass, enclosing.classes_hash,
382
- @store.classes_hash)
367
+ enclosing.add_class_or_module(klass, enclosing.classes_hash,
368
+ @store.classes_hash)
369
+ end
383
370
  end
384
- end
385
371
 
386
- klass.parent = self
372
+ klass.parent = self
387
373
 
388
- klass
389
- end
374
+ klass
375
+ end
390
376
 
391
- ##
392
- # Adds the class or module +mod+ to the modules or
393
- # classes Hash +self_hash+, and to +all_hash+ (either
394
- # <tt>TopLevel::modules_hash</tt> or <tt>TopLevel::classes_hash</tt>),
395
- # unless #done_documenting is +true+. Sets the #parent of +mod+
396
- # to +self+, and its #section to #current_section. Returns +mod+.
397
-
398
- def add_class_or_module(mod, self_hash, all_hash)
399
- mod.section = current_section # TODO declaring context? something is
400
- # wrong here...
401
- mod.parent = self
402
- mod.full_name = nil
403
- mod.store = @store
404
-
405
- unless @done_documenting then
406
- self_hash[mod.name] = mod
407
- # this must be done AFTER adding mod to its parent, so that the full
408
- # name is correct:
409
- all_hash[mod.full_name] = mod
410
- if @store.unmatched_constant_alias[mod.full_name] then
411
- to, file = @store.unmatched_constant_alias[mod.full_name]
412
- add_module_alias mod, mod.name, to, file
377
+ ##
378
+ # Adds the class or module +mod+ to the modules or
379
+ # classes Hash +self_hash+, and to +all_hash+ (either
380
+ # <tt>TopLevel::modules_hash</tt> or <tt>TopLevel::classes_hash</tt>),
381
+ # unless #done_documenting is +true+. Sets the #parent of +mod+
382
+ # to +self+, and its #section to #current_section. Returns +mod+.
383
+
384
+ def add_class_or_module(mod, self_hash, all_hash)
385
+ mod.section = current_section # TODO declaring context? something is
386
+ # wrong here...
387
+ mod.parent = self
388
+ mod.full_name = nil
389
+ mod.store = @store
390
+
391
+ unless @done_documenting
392
+ self_hash[mod.name] = mod
393
+ # this must be done AFTER adding mod to its parent, so that the full
394
+ # name is correct:
395
+ all_hash[mod.full_name] = mod
413
396
  end
397
+
398
+ mod
414
399
  end
415
400
 
416
- mod
417
- end
401
+ ##
402
+ # Adds +constant+ if not already there. If it is, updates the comment,
403
+ # value and/or is_alias_for of the known constant if they were empty/nil.
418
404
 
419
- ##
420
- # Adds +constant+ if not already there. If it is, updates the comment,
421
- # value and/or is_alias_for of the known constant if they were empty/nil.
405
+ def add_constant(constant)
406
+ return constant unless @document_self
422
407
 
423
- def add_constant(constant)
424
- return constant unless @document_self
408
+ # HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code)
409
+ # (this is a #ifdef: should be handled by the C parser)
410
+ known = @constants_hash[constant.name]
425
411
 
426
- # HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code)
427
- # (this is a #ifdef: should be handled by the C parser)
428
- known = @constants_hash[constant.name]
412
+ if known
413
+ known.comment = constant.comment if known.comment.empty?
429
414
 
430
- if known then
431
- known.comment = constant.comment if known.comment.empty?
415
+ known.value = constant.value if
416
+ known.value.nil? or known.value.strip.empty?
432
417
 
433
- known.value = constant.value if
434
- known.value.nil? or known.value.strip.empty?
418
+ constant.parent = self
419
+ known.is_alias_for ||= constant.is_alias_for
420
+ else
421
+ @constants_hash[constant.name] = constant
422
+ add_to @constants, constant
423
+ end
435
424
 
436
- constant.parent = self
437
- known.is_alias_for ||= constant.is_alias_for
438
- else
439
- @constants_hash[constant.name] = constant
440
- add_to @constants, constant
425
+ constant
441
426
  end
442
427
 
443
- constant
444
- end
428
+ ##
429
+ # Adds included module +include+ which should be an RDoc::Include
445
430
 
446
- ##
447
- # Adds included module +include+ which should be an RDoc::Include
431
+ def add_include(include)
432
+ add_to @includes, include
448
433
 
449
- def add_include(include)
450
- add_to @includes, include
434
+ include
435
+ end
451
436
 
452
- include
453
- end
437
+ ##
438
+ # Adds extension module +ext+ which should be an RDoc::Extend
454
439
 
455
- ##
456
- # Adds extension module +ext+ which should be an RDoc::Extend
440
+ def add_extend(ext)
441
+ add_to @extends, ext
457
442
 
458
- def add_extend(ext)
459
- add_to @extends, ext
443
+ ext
444
+ end
460
445
 
461
- ext
462
- end
446
+ ##
447
+ # Adds +method+ if not already there. If it is (as method or attribute),
448
+ # updates the comment if it was empty.
463
449
 
464
- ##
465
- # Adds +method+ if not already there. If it is (as method or attribute),
466
- # updates the comment if it was empty.
467
-
468
- def add_method(method)
469
- return method unless @document_self
470
-
471
- # HACK: avoid duplicate 'new' in io.c & struct.c (1.8.7 source code)
472
- key = method.pretty_name
473
- known = @methods_hash[key]
474
-
475
- if known then
476
- if @store then # otherwise we are loading
477
- known.comment = method.comment if known.comment.empty?
478
- previously = ", previously in #{known.file}" unless
479
- method.file == known.file
480
- @store.options.warn \
481
- "Duplicate method #{known.full_name} in #{method.file}#{previously}"
482
- end
483
- else
484
- @methods_hash[key] = method
485
- if @current_line_visibility
486
- method.visibility, @current_line_visibility = @current_line_visibility, nil
450
+ def add_method(method)
451
+ return method unless @document_self
452
+
453
+ # HACK: avoid duplicate 'new' in io.c & struct.c (1.8.7 source code)
454
+ key = method.pretty_name
455
+ known = @methods_hash[key]
456
+
457
+ if known
458
+ if @store # otherwise we are loading
459
+ known.comment = method.comment if known.comment.empty?
460
+ previously = ", previously in #{known.file}" unless
461
+ method.file == known.file
462
+ @store.options.warn \
463
+ "Duplicate method #{known.full_name} in #{method.file}#{previously}"
464
+ end
487
465
  else
488
- method.visibility = @visibility
466
+ @methods_hash[key] = method
467
+ add_to @method_list, method
468
+ resolve_aliases method
489
469
  end
490
- add_to @method_list, method
491
- resolve_aliases method
492
- end
493
470
 
494
- method
495
- end
471
+ method
472
+ end
496
473
 
497
- ##
498
- # Returns the owner context and local name for +constant_path+, creating
499
- # missing namespace modules. A leading +::+ resolves from the top-level.
500
- # This only resolves explicit context-tree paths; RDoc::Parser::Ruby has
501
- # parser-local lexical helpers for Ruby's nesting-dependent lookup.
474
+ ##
475
+ # Returns the owner context and local name for +constant_path+, creating
476
+ # missing namespace modules. A leading +::+ resolves from the top-level.
477
+ # This only resolves explicit context-tree paths; RDoc::Parser::Ruby has
478
+ # parser-local lexical helpers for Ruby's nesting-dependent lookup.
502
479
 
503
- def find_or_create_constant_owner_for_path(constant_path) # :nodoc:
504
- constant_path = constant_path.to_s
505
- owner = constant_path.start_with?('::') ? top_level : self
506
- constant_path = constant_path.delete_prefix('::')
480
+ def find_or_create_constant_owner_for_path(constant_path) # :nodoc:
481
+ constant_path = constant_path.to_s
482
+ owner = constant_path.start_with?('::') ? top_level : self
483
+ constant_path = constant_path.delete_prefix('::')
507
484
 
508
- owner_path, separator, name = constant_path.rpartition('::')
509
- owner = owner.find_or_create_namespace_path owner_path unless separator.empty?
485
+ owner_path, separator, name = constant_path.rpartition('::')
486
+ owner = owner.find_or_create_namespace_path owner_path unless separator.empty?
510
487
 
511
- [owner, name]
512
- end
488
+ [owner, name]
489
+ end
513
490
 
514
- ##
515
- # Finds or creates the module namespace path under this context.
491
+ ##
492
+ # Finds or creates the module namespace path under this context.
516
493
 
517
- def find_or_create_namespace_path(path) # :nodoc:
518
- path.to_s.split('::').inject(self) do |owner, name|
519
- owner.classes_hash[name] ||
520
- owner.modules_hash[name] ||
521
- owner.add_module(RDoc::NormalModule, name)
494
+ def find_or_create_namespace_path(path) # :nodoc:
495
+ path.to_s.split('::').inject(self) do |owner, name|
496
+ owner.classes_hash[name] ||
497
+ owner.modules_hash[name] ||
498
+ owner.add_module(NormalModule, name)
499
+ end
522
500
  end
523
- end
524
501
 
525
- ##
526
- # Adds a module named +name+. If RDoc already knows +name+ is a class then
527
- # that class is returned instead. See also #add_class.
502
+ ##
503
+ # Adds a module named +name+. If RDoc already knows +name+ is a class then
504
+ # that class is returned instead. See also #add_class.
528
505
 
529
- def add_module(class_type, name)
530
- if name.to_s.include?('::')
531
- owner, name = find_or_create_constant_owner_for_path name
532
- return owner.add_module class_type, name unless owner == self
533
- end
506
+ def add_module(class_type, name)
507
+ if name.to_s.include?('::')
508
+ owner, name = find_or_create_constant_owner_for_path name
509
+ return owner.add_module class_type, name unless owner == self
510
+ end
534
511
 
535
- mod = @classes[name] || @modules[name]
536
- return mod if mod
512
+ mod = @classes[name] || @modules[name]
513
+ return mod if mod
537
514
 
538
- full_name = child_name name
539
- mod = @store.modules_hash[full_name] || class_type.new(name)
515
+ full_name = child_name name
516
+ mod = @store.modules_hash[full_name] || class_type.new(name)
540
517
 
541
- add_class_or_module mod, @modules, @store.modules_hash
542
- end
518
+ add_class_or_module mod, @modules, @store.modules_hash
519
+ end
543
520
 
544
- ##
545
- # Adds a module by +RDoc::NormalModule+ instance. See also #add_module.
521
+ ##
522
+ # Adds a module by +RDoc::NormalModule+ instance. See also #add_module.
546
523
 
547
- def add_module_by_normal_module(mod)
548
- add_class_or_module mod, @modules, @store.modules_hash
549
- end
524
+ def add_module_by_normal_module(mod)
525
+ add_class_or_module mod, @modules, @store.modules_hash
526
+ end
550
527
 
551
- ##
552
- # Adds an alias from +from+ (a class or module) to +name+ which was defined
553
- # in +file+.
528
+ ##
529
+ # Adds an alias from +from+ (a class or module) to the constant +to+ which
530
+ # was defined in +file+.
554
531
 
555
- def add_module_alias(from, from_name, to, file)
556
- return from if @done_documenting
532
+ def add_module_alias(from, to, file)
533
+ return from if @done_documenting
557
534
 
558
- to_full_name = child_name to.name
535
+ to_full_name = child_name to.name
559
536
 
560
- # if we already know this name, don't register an alias:
561
- # see the metaprogramming in lib/active_support/basic_object.rb,
562
- # where we already know BasicObject is a class when we find
563
- # BasicObject = BlankSlate
564
- return from if @store.find_class_or_module to_full_name
537
+ # if we already know this name, don't register an alias:
538
+ # see the metaprogramming in lib/active_support/basic_object.rb,
539
+ # where we already know BasicObject is a class when we find
540
+ # BasicObject = BlankSlate
541
+ return from if @store.find_class_or_module to_full_name
565
542
 
566
- unless from
567
- @store.unmatched_constant_alias[child_name(from_name)] = [to, file]
568
- return to
569
- end
543
+ new_to = from.dup
544
+ new_to.name = to.name
545
+ new_to.full_name = nil
546
+ new_to.is_alias_for = from
570
547
 
571
- new_to = from.dup
572
- new_to.name = to.name
573
- new_to.full_name = nil
574
- new_to.is_alias_for = from
548
+ if new_to.module?
549
+ @store.modules_hash[to_full_name] = new_to
550
+ @modules[to.name] = new_to
551
+ else
552
+ @store.classes_hash[to_full_name] = new_to
553
+ @classes[to.name] = new_to
554
+ end
575
555
 
576
- if new_to.module? then
577
- @store.modules_hash[to_full_name] = new_to
578
- @modules[to.name] = new_to
579
- else
580
- @store.classes_hash[to_full_name] = new_to
581
- @classes[to.name] = new_to
556
+ # Registers a constant for this alias. The constant value and comment
557
+ # will be updated later, when the Ruby parser adds the constant
558
+ const = Constant.new to.name, nil, new_to.comment
559
+ const.record_location file
560
+ const.is_alias_for = from
561
+ add_constant const
562
+
563
+ new_to
582
564
  end
583
565
 
584
- # Registers a constant for this alias. The constant value and comment
585
- # will be updated later, when the Ruby parser adds the constant
586
- const = RDoc::Constant.new to.name, nil, new_to.comment
587
- const.record_location file
588
- const.is_alias_for = from
589
- add_constant const
566
+ ##
567
+ # Adds +require+ to this context's top level
590
568
 
591
- new_to
592
- end
569
+ def add_require(require)
570
+ return require unless @document_self
593
571
 
594
- ##
595
- # Adds +require+ to this context's top level
572
+ if TopLevel === self
573
+ add_to @requires, require
574
+ else
575
+ parent.add_require require
576
+ end
577
+ end
596
578
 
597
- def add_require(require)
598
- return require unless @document_self
579
+ ##
580
+ # Returns a section with +title+, creating it if it doesn't already exist.
581
+ # +comment+ will be appended to the section's comment.
582
+ #
583
+ # A section with a +title+ of +nil+ will return the default section.
584
+ #
585
+ # See also RDoc::Context::Section
599
586
 
600
- if RDoc::TopLevel === self then
601
- add_to @requires, require
602
- else
603
- parent.add_require require
587
+ def add_section(title, comment = nil)
588
+ if section = @sections[title]
589
+ section.add_comment comment if comment
590
+ else
591
+ section = Section.new self, title, comment, @store
592
+ @sections[title] = section
593
+ end
594
+
595
+ section
604
596
  end
605
- end
606
597
 
607
- ##
608
- # Returns a section with +title+, creating it if it doesn't already exist.
609
- # +comment+ will be appended to the section's comment.
610
- #
611
- # A section with a +title+ of +nil+ will return the default section.
612
- #
613
- # See also RDoc::Context::Section
614
-
615
- def add_section(title, comment = nil)
616
- if section = @sections[title] then
617
- section.add_comment comment if comment
618
- else
619
- section = Section.new self, title, comment, @store
620
- @sections[title] = section
621
- end
622
-
623
- section
624
- end
598
+ ##
599
+ # Adds +thing+ to the collection +array+
625
600
 
626
- ##
627
- # Adds +thing+ to the collection +array+
601
+ def add_to(array, thing)
602
+ array << thing if @document_self
628
603
 
629
- def add_to(array, thing)
630
- array << thing if @document_self
604
+ thing.parent = self
605
+ thing.store = @store if @store
606
+ thing.section = current_section
607
+ end
631
608
 
632
- thing.parent = self
633
- thing.store = @store if @store
634
- thing.section = current_section
635
- end
609
+ ##
610
+ # Is there any content?
611
+ #
612
+ # This means any of: comment, aliases, methods, attributes, external
613
+ # aliases, require, constant.
614
+ #
615
+ # Includes and extends are also checked unless <tt>includes == false</tt>.
616
+
617
+ def any_content(includes = true)
618
+ @any_content ||= !(
619
+ @comment.empty? &&
620
+ @method_list.empty? &&
621
+ @attributes.empty? &&
622
+ @aliases.empty? &&
623
+ @external_aliases.empty? &&
624
+ @requires.empty? &&
625
+ @constants.empty?
626
+ )
627
+ @any_content || (includes && !(@includes + @extends).empty? )
628
+ end
636
629
 
637
- ##
638
- # Is there any content?
639
- #
640
- # This means any of: comment, aliases, methods, attributes, external
641
- # aliases, require, constant.
642
- #
643
- # Includes and extends are also checked unless <tt>includes == false</tt>.
644
-
645
- def any_content(includes = true)
646
- @any_content ||= !(
647
- @comment.empty? &&
648
- @method_list.empty? &&
649
- @attributes.empty? &&
650
- @aliases.empty? &&
651
- @external_aliases.empty? &&
652
- @requires.empty? &&
653
- @constants.empty?
654
- )
655
- @any_content || (includes && !(@includes + @extends).empty? )
656
- end
630
+ ##
631
+ # Creates the full name for a child with +name+
657
632
 
658
- ##
659
- # Creates the full name for a child with +name+
633
+ def child_name(name)
634
+ if name =~ /^:+/
635
+ $' #'
636
+ elsif TopLevel === self
637
+ name
638
+ else
639
+ "#{self.full_name}::#{name}"
640
+ end
641
+ end
660
642
 
661
- def child_name(name)
662
- if name =~ /^:+/
663
- $' #'
664
- elsif RDoc::TopLevel === self then
665
- name
666
- else
667
- "#{self.full_name}::#{name}"
643
+ ##
644
+ # Class methods
645
+
646
+ def class_method_list
647
+ method_list.select { |a| a.singleton }
668
648
  end
669
- end
670
649
 
671
- ##
672
- # Class methods
650
+ ##
651
+ # Array of classes in this context
673
652
 
674
- def class_method_list
675
- method_list.select { |a| a.singleton }
676
- end
653
+ def classes
654
+ @classes.values
655
+ end
677
656
 
678
- ##
679
- # Array of classes in this context
657
+ ##
658
+ # All classes and modules in this namespace
680
659
 
681
- def classes
682
- @classes.values
683
- end
660
+ def classes_and_modules
661
+ classes + modules
662
+ end
684
663
 
685
- ##
686
- # All classes and modules in this namespace
664
+ ##
665
+ # Hash of classes keyed by class name
687
666
 
688
- def classes_and_modules
689
- classes + modules
690
- end
667
+ def classes_hash
668
+ @classes
669
+ end
691
670
 
692
- ##
693
- # Hash of classes keyed by class name
671
+ ##
672
+ # The current documentation section that new items will be added to. If
673
+ # temporary_section is available it will be used.
694
674
 
695
- def classes_hash
696
- @classes
697
- end
675
+ def current_section
676
+ if section = @temporary_section
677
+ @temporary_section = nil
678
+ else
679
+ section = @current_section
680
+ end
698
681
 
699
- ##
700
- # The current documentation section that new items will be added to. If
701
- # temporary_section is available it will be used.
682
+ section
683
+ end
702
684
 
703
- def current_section
704
- if section = @temporary_section then
705
- @temporary_section = nil
706
- else
707
- section = @current_section
685
+ def display(method_attr) # :nodoc:
686
+ if method_attr.is_a? Attr
687
+ "#{method_attr.definition} #{method_attr.pretty_name}"
688
+ else
689
+ "method #{method_attr.pretty_name}"
690
+ end
708
691
  end
709
692
 
710
- section
711
- end
693
+ ##
694
+ # Iterator for ancestors for duck-typing. Does nothing. See
695
+ # RDoc::ClassModule#each_ancestor.
696
+ #
697
+ # This method exists to make it easy to work with Context subclasses that
698
+ # aren't part of RDoc.
712
699
 
713
- def display(method_attr) # :nodoc:
714
- if method_attr.is_a? RDoc::Attr
715
- "#{method_attr.definition} #{method_attr.pretty_name}"
716
- else
717
- "method #{method_attr.pretty_name}"
700
+ def each_ancestor(&_) # :nodoc:
718
701
  end
719
- end
720
702
 
721
- ##
722
- # Iterator for ancestors for duck-typing. Does nothing. See
723
- # RDoc::ClassModule#each_ancestor.
724
- #
725
- # This method exists to make it easy to work with Context subclasses that
726
- # aren't part of RDoc.
703
+ ##
704
+ # Iterator for classes and modules
727
705
 
728
- def each_ancestor(&_) # :nodoc:
729
- end
706
+ def each_classmodule(&block) # :yields: module
707
+ classes_and_modules.sort.each(&block)
708
+ end
730
709
 
731
- ##
732
- # Iterator for classes and modules
710
+ ##
711
+ # Iterator for methods
733
712
 
734
- def each_classmodule(&block) # :yields: module
735
- classes_and_modules.sort.each(&block)
736
- end
713
+ def each_method # :yields: method
714
+ return enum_for __method__ unless block_given?
737
715
 
738
- ##
739
- # Iterator for methods
716
+ @method_list.sort.each { |m| yield m }
717
+ end
740
718
 
741
- def each_method # :yields: method
742
- return enum_for __method__ unless block_given?
719
+ ##
720
+ # Iterator for each section's contents sorted by title. The +section+, the
721
+ # section's +constants+ and the sections +attributes+ are yielded. The
722
+ # +constants+ and +attributes+ collections are sorted.
723
+ #
724
+ # To retrieve methods in a section use #methods_by_type with the optional
725
+ # +section+ parameter.
726
+ #
727
+ # NOTE: Do not edit collections yielded by this method
743
728
 
744
- @method_list.sort.each { |m| yield m }
745
- end
729
+ def each_section # :yields: section, constants, attributes
730
+ return enum_for __method__ unless block_given?
746
731
 
747
- ##
748
- # Iterator for each section's contents sorted by title. The +section+, the
749
- # section's +constants+ and the sections +attributes+ are yielded. The
750
- # +constants+ and +attributes+ collections are sorted.
751
- #
752
- # To retrieve methods in a section use #methods_by_type with the optional
753
- # +section+ parameter.
754
- #
755
- # NOTE: Do not edit collections yielded by this method
732
+ constants = @constants.group_by do |constant| constant.section end
733
+ attributes = @attributes.group_by do |attribute| attribute.section end
756
734
 
757
- def each_section # :yields: section, constants, attributes
758
- return enum_for __method__ unless block_given?
735
+ constants.default = []
736
+ attributes.default = []
759
737
 
760
- constants = @constants.group_by do |constant| constant.section end
761
- attributes = @attributes.group_by do |attribute| attribute.section end
738
+ sort_sections.each do |section|
739
+ yield section, constants[section].select(&:display?).sort, attributes[section].select(&:display?).sort
740
+ end
741
+ end
762
742
 
763
- constants.default = []
764
- attributes.default = []
743
+ ##
744
+ # Finds an attribute +name+ with singleton value +singleton+.
765
745
 
766
- sort_sections.each do |section|
767
- yield section, constants[section].select(&:display?).sort, attributes[section].select(&:display?).sort
746
+ def find_attribute(name, singleton)
747
+ name = $1 if name =~ /^(.*)=$/
748
+ @attributes.find { |a| a.name == name && a.singleton == singleton }
768
749
  end
769
- end
770
750
 
771
- ##
772
- # Finds an attribute +name+ with singleton value +singleton+.
751
+ ##
752
+ # Finds an attribute with +name+ in this context
773
753
 
774
- def find_attribute(name, singleton)
775
- name = $1 if name =~ /^(.*)=$/
776
- @attributes.find { |a| a.name == name && a.singleton == singleton }
777
- end
754
+ def find_attribute_named(name)
755
+ case name
756
+ when /\A#/
757
+ find_attribute name[1..-1], false
758
+ when /\A::/
759
+ find_attribute name[2..-1], true
760
+ else
761
+ @attributes.find { |a| a.name == name }
762
+ end
763
+ end
778
764
 
779
- ##
780
- # Finds an attribute with +name+ in this context
765
+ ##
766
+ # Finds a class method with +name+ in this context
781
767
 
782
- def find_attribute_named(name)
783
- case name
784
- when /\A#/ then
785
- find_attribute name[1..-1], false
786
- when /\A::/ then
787
- find_attribute name[2..-1], true
788
- else
789
- @attributes.find { |a| a.name == name }
768
+ def find_class_method_named(name)
769
+ @method_list.find { |meth| meth.singleton && meth.name == name }
790
770
  end
791
- end
792
771
 
793
- ##
794
- # Finds a class method with +name+ in this context
772
+ ##
773
+ # Finds a constant with +name+ in this context
795
774
 
796
- def find_class_method_named(name)
797
- @method_list.find { |meth| meth.singleton && meth.name == name }
798
- end
775
+ def find_constant_named(name)
776
+ @constants.find do |m|
777
+ m.name == name || m.full_name == name
778
+ end
779
+ end
799
780
 
800
- ##
801
- # Finds a constant with +name+ in this context
781
+ ##
782
+ # Tries to find a module at a higher scope.
783
+ # But parent is not always a higher module nesting scope, so the result is not correct.
784
+ # Parent chain can only represent last-opened nesting, and may be broken in some cases.
785
+ # The Ruby parser does not represent module nesting with the parent chain.
802
786
 
803
- def find_constant_named(name)
804
- @constants.find do |m|
805
- m.name == name || m.full_name == name
787
+ def find_enclosing_module_named(name)
788
+ parent && parent.find_module_named(name)
806
789
  end
807
- end
808
790
 
809
- ##
810
- # Tries to find a module at a higher scope.
811
- # But parent is not always a higher module nesting scope, so the result is not correct.
812
- # Parent chain can only represent last-opened nesting, and may be broken in some cases.
813
- # The Ruby parser does not represent module nesting with the parent chain.
791
+ ##
792
+ # Finds an external alias +name+ with singleton value +singleton+.
814
793
 
815
- def find_enclosing_module_named(name)
816
- parent && parent.find_module_named(name)
817
- end
794
+ def find_external_alias(name, singleton)
795
+ @external_aliases.find { |m| m.name == name && m.singleton == singleton }
796
+ end
818
797
 
819
- ##
820
- # Finds an external alias +name+ with singleton value +singleton+.
798
+ ##
799
+ # Finds an external alias with +name+ in this context
821
800
 
822
- def find_external_alias(name, singleton)
823
- @external_aliases.find { |m| m.name == name && m.singleton == singleton }
824
- end
801
+ def find_external_alias_named(name)
802
+ case name
803
+ when /\A#/
804
+ find_external_alias name[1..-1], false
805
+ when /\A::/
806
+ find_external_alias name[2..-1], true
807
+ else
808
+ @external_aliases.find { |a| a.name == name }
809
+ end
810
+ end
825
811
 
826
- ##
827
- # Finds an external alias with +name+ in this context
812
+ ##
813
+ # Finds an instance method with +name+ in this context
828
814
 
829
- def find_external_alias_named(name)
830
- case name
831
- when /\A#/ then
832
- find_external_alias name[1..-1], false
833
- when /\A::/ then
834
- find_external_alias name[2..-1], true
835
- else
836
- @external_aliases.find { |a| a.name == name }
815
+ def find_instance_method_named(name)
816
+ @method_list.find { |meth| !meth.singleton && meth.name == name }
837
817
  end
838
- end
839
818
 
840
- ##
841
- # Finds an instance method with +name+ in this context
819
+ ##
820
+ # Finds a method, constant, attribute, external alias, module or file
821
+ # named +symbol+ in this context.
822
+
823
+ def find_local_symbol(symbol)
824
+ find_method_named(symbol) or
825
+ find_constant_named(symbol) or
826
+ find_attribute_named(symbol) or
827
+ find_external_alias_named(symbol) or
828
+ find_module_named(symbol) or
829
+ @store.find_file_named(symbol)
830
+ end
842
831
 
843
- def find_instance_method_named(name)
844
- @method_list.find { |meth| !meth.singleton && meth.name == name }
845
- end
832
+ ##
833
+ # Finds a method named +name+ with singleton value +singleton+.
846
834
 
847
- ##
848
- # Finds a method, constant, attribute, external alias, module or file
849
- # named +symbol+ in this context.
850
-
851
- def find_local_symbol(symbol)
852
- find_method_named(symbol) or
853
- find_constant_named(symbol) or
854
- find_attribute_named(symbol) or
855
- find_external_alias_named(symbol) or
856
- find_module_named(symbol) or
857
- @store.find_file_named(symbol)
858
- end
835
+ def find_method(name, singleton)
836
+ @method_list.find { |m|
837
+ if m.singleton
838
+ m.name == name && m.singleton == singleton
839
+ else
840
+ m.name == name && !m.singleton && !singleton
841
+ end
842
+ }
843
+ end
859
844
 
860
- ##
861
- # Finds a method named +name+ with singleton value +singleton+.
845
+ ##
846
+ # Finds a instance or module method with +name+ in this context
862
847
 
863
- def find_method(name, singleton)
864
- @method_list.find { |m|
865
- if m.singleton
866
- m.name == name && m.singleton == singleton
848
+ def find_method_named(name)
849
+ case name
850
+ when /\A#/
851
+ find_method name[1..-1], false
852
+ when /\A::/
853
+ find_method name[2..-1], true
867
854
  else
868
- m.name == name && !m.singleton && !singleton
855
+ @method_list.find { |meth| meth.name == name }
869
856
  end
870
- }
871
- end
857
+ end
872
858
 
873
- ##
874
- # Finds a instance or module method with +name+ in this context
859
+ ##
860
+ # Find a module with +name+ trying to using ruby's scoping rules.
861
+ # find_enclosing_module_named cannot use ruby's scoping so the result is not correct.
875
862
 
876
- def find_method_named(name)
877
- case name
878
- when /\A#/ then
879
- find_method name[1..-1], false
880
- when /\A::/ then
881
- find_method name[2..-1], true
882
- else
883
- @method_list.find { |meth| meth.name == name }
863
+ def find_module_named(name)
864
+ res = get_module_named(name)
865
+ return res if res
866
+ return self if self.name == name
867
+ find_enclosing_module_named name
884
868
  end
885
- end
886
-
887
- ##
888
- # Find a module with +name+ trying to using ruby's scoping rules.
889
- # find_enclosing_module_named cannot use ruby's scoping so the result is not correct.
890
-
891
- def find_module_named(name)
892
- res = get_module_named(name)
893
- return res if res
894
- return self if self.name == name
895
- find_enclosing_module_named name
896
- end
897
869
 
898
- # Get a module named +name+ in this context
899
- # Don't look up for higher module nesting scopes. RDoc::Context doesn't have that information.
870
+ # Get a module named +name+ in this context
871
+ # Don't look up for higher module nesting scopes. RDoc::Context doesn't have that information.
900
872
 
901
- def get_module_named(name)
902
- @modules[name] || @classes[name]
903
- end
873
+ def get_module_named(name)
874
+ @modules[name] || @classes[name]
875
+ end
904
876
 
905
- ##
906
- # Look up +symbol+, first as a module, then as a local symbol.
877
+ ##
878
+ # Look up +symbol+, first as a module, then as a local symbol.
907
879
 
908
- def find_symbol(symbol)
909
- find_symbol_module(symbol) || find_local_symbol(symbol)
910
- end
880
+ def find_symbol(symbol)
881
+ find_symbol_module(symbol) || find_local_symbol(symbol)
882
+ end
911
883
 
912
- ##
913
- # Look up a module named +symbol+.
914
-
915
- def find_symbol_module(symbol)
916
- result = nil
917
-
918
- # look for a class or module 'symbol'
919
- case symbol
920
- when /^::/ then
921
- result = @store.find_class_or_module symbol
922
- when /^(\w+):+(.+)$/
923
- suffix = $2
924
- top = $1
925
- searched = self
926
- while searched do
927
- mod = searched.find_module_named(top)
928
- break unless mod
929
- result = @store.find_class_or_module "#{mod.full_name}::#{suffix}"
930
- break if result || searched.is_a?(RDoc::TopLevel)
931
- searched = searched.parent
932
- end
933
- else
934
- searched = self
935
- while searched do
936
- result = searched.find_module_named(symbol)
937
- break if result || searched.is_a?(RDoc::TopLevel)
938
- searched = searched.parent
884
+ ##
885
+ # Look up a module named +symbol+.
886
+
887
+ def find_symbol_module(symbol)
888
+ result = nil
889
+
890
+ # look for a class or module 'symbol'
891
+ case symbol
892
+ when /^::/
893
+ result = @store.find_class_or_module symbol
894
+ when /^(\w+):+(.+)$/
895
+ suffix = $2
896
+ top = $1
897
+ searched = self
898
+ while searched do
899
+ mod = searched.find_module_named(top)
900
+ break unless mod
901
+ result = @store.find_class_or_module "#{mod.full_name}::#{suffix}"
902
+ break if result || searched.is_a?(TopLevel)
903
+ searched = searched.parent
904
+ end
905
+ else
906
+ searched = self
907
+ while searched do
908
+ result = searched.find_module_named(symbol)
909
+ break if result || searched.is_a?(TopLevel)
910
+ searched = searched.parent
911
+ end
939
912
  end
913
+
914
+ result
940
915
  end
941
916
 
942
- result
943
- end
917
+ ##
918
+ # The full name for this context. This method is overridden by subclasses.
944
919
 
945
- ##
946
- # The full name for this context. This method is overridden by subclasses.
920
+ def full_name
921
+ '(unknown)'
922
+ end
947
923
 
948
- def full_name
949
- '(unknown)'
950
- end
924
+ ##
925
+ # Does this context and its methods and constants all have documentation?
926
+ #
927
+ # (Yes, fully documented doesn't mean everything.)
951
928
 
952
- ##
953
- # Does this context and its methods and constants all have documentation?
954
- #
955
- # (Yes, fully documented doesn't mean everything.)
956
-
957
- def fully_documented?
958
- documented? and
959
- attributes.all? { |a| a.documented? } and
960
- method_list.all? { |m| m.documented? } and
961
- constants.all? { |c| c.documented? }
962
- end
929
+ def fully_documented?
930
+ documented? and
931
+ attributes.all? { |a| a.documented? } and
932
+ method_list.all? { |m| m.documented? } and
933
+ constants.all? { |c| c.documented? }
934
+ end
963
935
 
964
- ##
965
- # URL for this with a +prefix+
936
+ ##
937
+ # URL for this with a +prefix+
966
938
 
967
- def http_url
968
- path = name_for_path
969
- path = path.gsub(/<<\s*(\w*)/, 'from-\1') if path =~ /<</
970
- path = path.split('::')
939
+ def http_url
940
+ path = name_for_path
941
+ path = path.gsub(/<<\s*(\w*)/, 'from-\1') if path =~ /<</
942
+ path = path.split('::')
971
943
 
972
- File.join(*path.compact) + '.html'
973
- end
944
+ File.join(*path.compact) + '.html'
945
+ end
974
946
 
975
- ##
976
- # Instance methods
947
+ ##
948
+ # Instance methods
977
949
 
978
- def instance_methods
979
- method_list.reject { |a| a.singleton }
980
- end
950
+ def instance_methods
951
+ method_list.reject { |a| a.singleton }
952
+ end
981
953
 
982
- ##
983
- # Breaks method_list into a nested hash by type (<tt>'class'</tt> or
984
- # <tt>'instance'</tt>) and visibility (+:public+, +:protected+, +:private+).
985
- #
986
- # If +section+ is provided only methods in that RDoc::Context::Section will
987
- # be returned.
988
-
989
- def methods_by_type(section = nil)
990
- methods = {}
991
-
992
- TYPES.each do |type|
993
- visibilities = {}
994
- RDoc::VISIBILITIES.each do |vis|
995
- visibilities[vis] = []
954
+ ##
955
+ # Breaks method_list into a nested hash by type (<tt>'class'</tt> or
956
+ # <tt>'instance'</tt>) and visibility (+:public+, +:protected+, +:private+).
957
+ #
958
+ # If +section+ is provided only methods in that RDoc::Context::Section will
959
+ # be returned.
960
+
961
+ def methods_by_type(section = nil)
962
+ methods = {}
963
+
964
+ TYPES.each do |type|
965
+ visibilities = {}
966
+ VISIBILITIES.each do |vis|
967
+ visibilities[vis] = []
968
+ end
969
+
970
+ methods[type] = visibilities
996
971
  end
997
972
 
998
- methods[type] = visibilities
999
- end
973
+ each_method do |method|
974
+ next if section and not method.section == section
975
+ methods[method.type][method.visibility] << method
976
+ end
1000
977
 
1001
- each_method do |method|
1002
- next if section and not method.section == section
1003
- methods[method.type][method.visibility] << method
978
+ methods
1004
979
  end
1005
980
 
1006
- methods
1007
- end
981
+ ##
982
+ # Yields AnyMethod and Attr entries matching the list of names in +methods+.
1008
983
 
1009
- ##
1010
- # Yields AnyMethod and Attr entries matching the list of names in +methods+.
984
+ def methods_matching(methods, singleton = false, &block)
985
+ (@method_list + @attributes).each do |m|
986
+ yield m if methods.include?(m.name) and m.singleton == singleton
987
+ end
1011
988
 
1012
- def methods_matching(methods, singleton = false, &block)
1013
- (@method_list + @attributes).each do |m|
1014
- yield m if methods.include?(m.name) and m.singleton == singleton
989
+ each_ancestor do |parent|
990
+ parent.methods_matching(methods, singleton, &block)
991
+ end
1015
992
  end
1016
993
 
1017
- each_ancestor do |parent|
1018
- parent.methods_matching(methods, singleton, &block)
994
+ ##
995
+ # Array of modules in this context
996
+
997
+ def modules
998
+ @modules.values
1019
999
  end
1020
- end
1021
1000
 
1022
- ##
1023
- # Array of modules in this context
1001
+ ##
1002
+ # Hash of modules keyed by module name
1024
1003
 
1025
- def modules
1026
- @modules.values
1027
- end
1004
+ def modules_hash
1005
+ @modules
1006
+ end
1028
1007
 
1029
- ##
1030
- # Hash of modules keyed by module name
1008
+ ##
1009
+ # Name to use to generate the url.
1010
+ # <tt>#full_name</tt> by default.
1031
1011
 
1032
- def modules_hash
1033
- @modules
1034
- end
1012
+ def name_for_path
1013
+ full_name
1014
+ end
1035
1015
 
1036
- ##
1037
- # Name to use to generate the url.
1038
- # <tt>#full_name</tt> by default.
1016
+ ##
1017
+ # Record +top_level+ as a file +self+ is in.
1039
1018
 
1040
- def name_for_path
1041
- full_name
1042
- end
1019
+ def record_location(top_level)
1020
+ @in_files << top_level unless @in_files.include?(top_level)
1021
+ end
1043
1022
 
1044
- ##
1045
- # Changes the visibility for new methods to +visibility+
1023
+ ##
1024
+ # Should we remove this context from the documentation?
1025
+ #
1026
+ # The answer is yes if:
1027
+ # * #received_nodoc is +true+
1028
+ # * #any_content is +false+ (not counting includes)
1029
+ # * All #includes are modules (not a string), and their module has
1030
+ # <tt>#remove_from_documentation? == true</tt>
1031
+ # * All classes and modules have <tt>#remove_from_documentation? == true</tt>
1032
+
1033
+ def remove_from_documentation?
1034
+ # Contexts that are still ignored here were created inside a :stopdoc:
1035
+ # region and never received documentable contents afterwards
1036
+ @remove_from_documentation ||=
1037
+ (@received_nodoc || @ignored) &&
1038
+ !any_content(false) &&
1039
+ @includes.all? { |i| !i.module.is_a?(String) && i.module.remove_from_documentation? } &&
1040
+ classes_and_modules.all? { |cm| cm.remove_from_documentation? }
1041
+ end
1046
1042
 
1047
- def ongoing_visibility=(visibility)
1048
- @visibility = visibility
1049
- end
1043
+ ##
1044
+ # Removes methods and attributes with a visibility less than +min_visibility+.
1045
+ #--
1046
+ # TODO mark the visibility of attributes in the template (if not public?)
1050
1047
 
1051
- ##
1052
- # Record +top_level+ as a file +self+ is in.
1048
+ def remove_invisible(min_visibility)
1049
+ return if [:private, :nodoc].include? min_visibility
1050
+ remove_invisible_in @method_list, min_visibility
1051
+ remove_invisible_in @attributes, min_visibility
1052
+ remove_invisible_in @constants, min_visibility
1053
+ end
1053
1054
 
1054
- def record_location(top_level)
1055
- @in_files << top_level unless @in_files.include?(top_level)
1056
- end
1055
+ ##
1056
+ # Only called when min_visibility == :public or :private
1057
1057
 
1058
- ##
1059
- # Should we remove this context from the documentation?
1060
- #
1061
- # The answer is yes if:
1062
- # * #received_nodoc is +true+
1063
- # * #any_content is +false+ (not counting includes)
1064
- # * All #includes are modules (not a string), and their module has
1065
- # <tt>#remove_from_documentation? == true</tt>
1066
- # * All classes and modules have <tt>#remove_from_documentation? == true</tt>
1067
-
1068
- def remove_from_documentation?
1069
- @remove_from_documentation ||=
1070
- @received_nodoc &&
1071
- !any_content(false) &&
1072
- @includes.all? { |i| !i.module.is_a?(String) && i.module.remove_from_documentation? } &&
1073
- classes_and_modules.all? { |cm| cm.remove_from_documentation? }
1074
- end
1058
+ def remove_invisible_in(array, min_visibility) # :nodoc:
1059
+ if min_visibility == :public
1060
+ array.reject! { |e|
1061
+ e.visibility != :public and not e.force_documentation
1062
+ }
1063
+ else
1064
+ array.reject! { |e|
1065
+ e.visibility == :private and not e.force_documentation
1066
+ }
1067
+ end
1068
+ end
1075
1069
 
1076
- ##
1077
- # Removes methods and attributes with a visibility less than +min_visibility+.
1078
- #--
1079
- # TODO mark the visibility of attributes in the template (if not public?)
1080
-
1081
- def remove_invisible(min_visibility)
1082
- return if [:private, :nodoc].include? min_visibility
1083
- remove_invisible_in @method_list, min_visibility
1084
- remove_invisible_in @attributes, min_visibility
1085
- remove_invisible_in @constants, min_visibility
1086
- end
1070
+ ##
1071
+ # Tries to resolve unmatched aliases when a method or attribute has just
1072
+ # been added.
1073
+
1074
+ def resolve_aliases(added)
1075
+ # resolve any pending unmatched aliases
1076
+ key = added.pretty_name
1077
+ unmatched_alias_list = @unmatched_alias_lists[key]
1078
+ return unless unmatched_alias_list
1079
+ unmatched_alias_list.each do |unmatched_alias|
1080
+ added.add_alias unmatched_alias, self
1081
+ @external_aliases.delete unmatched_alias
1082
+ end
1083
+ @unmatched_alias_lists.delete key
1084
+ end
1087
1085
 
1088
- ##
1089
- # Only called when min_visibility == :public or :private
1086
+ ##
1087
+ # Returns RDoc::Context::Section objects referenced in this context for use
1088
+ # in a table of contents.
1090
1089
 
1091
- def remove_invisible_in(array, min_visibility) # :nodoc:
1092
- if min_visibility == :public then
1093
- array.reject! { |e|
1094
- e.visibility != :public and not e.force_documentation
1095
- }
1096
- else
1097
- array.reject! { |e|
1098
- e.visibility == :private and not e.force_documentation
1099
- }
1100
- end
1101
- end
1090
+ def section_contents
1091
+ used_sections = {}
1102
1092
 
1103
- ##
1104
- # Tries to resolve unmatched aliases when a method or attribute has just
1105
- # been added.
1106
-
1107
- def resolve_aliases(added)
1108
- # resolve any pending unmatched aliases
1109
- key = added.pretty_name
1110
- unmatched_alias_list = @unmatched_alias_lists[key]
1111
- return unless unmatched_alias_list
1112
- unmatched_alias_list.each do |unmatched_alias|
1113
- added.add_alias unmatched_alias, self
1114
- @external_aliases.delete unmatched_alias
1115
- end
1116
- @unmatched_alias_lists.delete key
1117
- end
1093
+ each_method do |method|
1094
+ next unless method.display?
1118
1095
 
1119
- ##
1120
- # Returns RDoc::Context::Section objects referenced in this context for use
1121
- # in a table of contents.
1096
+ used_sections[method.section] = true
1097
+ end
1122
1098
 
1123
- def section_contents
1124
- used_sections = {}
1099
+ # order found sections
1100
+ sections = sort_sections.select do |section|
1101
+ used_sections[section]
1102
+ end
1125
1103
 
1126
- each_method do |method|
1127
- next unless method.display?
1104
+ # only the default section is used
1105
+ return [] if
1106
+ sections.length == 1 and not sections.first.title
1128
1107
 
1129
- used_sections[method.section] = true
1108
+ sections
1130
1109
  end
1131
1110
 
1132
- # order found sections
1133
- sections = sort_sections.select do |section|
1134
- used_sections[section]
1111
+ ##
1112
+ # Sections in this context
1113
+
1114
+ def sections
1115
+ @sections.values
1135
1116
  end
1136
1117
 
1137
- # only the default section is used
1138
- return [] if
1139
- sections.length == 1 and not sections.first.title
1118
+ def sections_hash # :nodoc:
1119
+ @sections
1120
+ end
1140
1121
 
1141
- sections
1142
- end
1122
+ ##
1123
+ # Sets the current section to a section with +title+. See also #add_section
1143
1124
 
1144
- ##
1145
- # Sections in this context
1125
+ def set_current_section(title, comment)
1126
+ @current_section = add_section title, comment
1127
+ end
1146
1128
 
1147
- def sections
1148
- @sections.values
1149
- end
1129
+ ##
1130
+ # Given an array +methods+ of method names, set the visibility of each to
1131
+ # +visibility+
1150
1132
 
1151
- def sections_hash # :nodoc:
1152
- @sections
1153
- end
1133
+ def set_visibility_for(methods, visibility, singleton = false)
1134
+ methods_matching methods, singleton do |m|
1135
+ m.visibility = visibility
1136
+ end
1137
+ end
1154
1138
 
1155
- ##
1156
- # Sets the current section to a section with +title+. See also #add_section
1139
+ ##
1140
+ # Given an array +names+ of constants, set the visibility of each constant to
1141
+ # +visibility+
1157
1142
 
1158
- def set_current_section(title, comment)
1159
- @current_section = add_section title, comment
1160
- end
1143
+ def set_constant_visibility_for(names, visibility)
1144
+ names.each do |name|
1145
+ constant = @constants_hash[name] or next
1146
+ constant.visibility = visibility
1147
+ end
1148
+ end
1161
1149
 
1162
- ##
1163
- # Given an array +methods+ of method names, set the visibility of each to
1164
- # +visibility+
1150
+ ##
1151
+ # Sorts sections alphabetically (default) or in TomDoc fashion (none,
1152
+ # Public, Internal, Deprecated)
1165
1153
 
1166
- def set_visibility_for(methods, visibility, singleton = false)
1167
- methods_matching methods, singleton do |m|
1168
- m.visibility = visibility
1169
- end
1170
- end
1154
+ def sort_sections
1155
+ titles = @sections.map { |title, _| title }
1171
1156
 
1172
- ##
1173
- # Given an array +names+ of constants, set the visibility of each constant to
1174
- # +visibility+
1157
+ if titles.length > 1 and
1158
+ TOMDOC_TITLES_SORT ==
1159
+ (titles | TOMDOC_TITLES).sort_by { |title| title.to_s }
1160
+ @sections.values_at(*TOMDOC_TITLES).compact
1161
+ else
1162
+ @sections.sort_by { |title, _|
1163
+ title.to_s
1164
+ }.map { |_, section|
1165
+ section
1166
+ }
1167
+ end
1168
+ end
1175
1169
 
1176
- def set_constant_visibility_for(names, visibility)
1177
- names.each do |name|
1178
- constant = @constants_hash[name] or next
1179
- constant.visibility = visibility
1170
+ def to_s # :nodoc:
1171
+ "#{self.class.name} #{self.full_name}"
1180
1172
  end
1181
- end
1182
1173
 
1183
- ##
1184
- # Sorts sections alphabetically (default) or in TomDoc fashion (none,
1185
- # Public, Internal, Deprecated)
1186
-
1187
- def sort_sections
1188
- titles = @sections.map { |title, _| title }
1189
-
1190
- if titles.length > 1 and
1191
- TOMDOC_TITLES_SORT ==
1192
- (titles | TOMDOC_TITLES).sort_by { |title| title.to_s } then
1193
- @sections.values_at(*TOMDOC_TITLES).compact
1194
- else
1195
- @sections.sort_by { |title, _|
1196
- title.to_s
1197
- }.map { |_, section|
1198
- section
1199
- }
1174
+ ##
1175
+ # Return the TopLevel that owns us
1176
+ #--
1177
+ # FIXME we can be 'owned' by several TopLevel (see #record_location &
1178
+ # #in_files)
1179
+
1180
+ def top_level
1181
+ return @top_level if defined? @top_level
1182
+ @top_level = self
1183
+ @top_level = @top_level.parent until TopLevel === @top_level
1184
+ @top_level
1200
1185
  end
1201
- end
1202
1186
 
1203
- def to_s # :nodoc:
1204
- "#{self.class.name} #{self.full_name}"
1205
- end
1187
+ ##
1188
+ # Upgrades NormalModule +mod+ in +enclosing+ to a +class_type+
1206
1189
 
1207
- ##
1208
- # Return the TopLevel that owns us
1209
- #--
1210
- # FIXME we can be 'owned' by several TopLevel (see #record_location &
1211
- # #in_files)
1212
-
1213
- def top_level
1214
- return @top_level if defined? @top_level
1215
- @top_level = self
1216
- @top_level = @top_level.parent until RDoc::TopLevel === @top_level
1217
- @top_level
1218
- end
1190
+ def upgrade_to_class(mod, class_type, enclosing)
1191
+ enclosing.modules_hash.delete mod.name
1219
1192
 
1220
- ##
1221
- # Upgrades NormalModule +mod+ in +enclosing+ to a +class_type+
1193
+ klass = ClassModule.from_module class_type, mod
1194
+ klass.store = @store
1222
1195
 
1223
- def upgrade_to_class(mod, class_type, enclosing)
1224
- enclosing.modules_hash.delete mod.name
1196
+ # if it was there, then we keep it even if done_documenting
1197
+ @store.classes_hash[mod.full_name] = klass
1198
+ enclosing.classes_hash[mod.name] = klass
1225
1199
 
1226
- klass = RDoc::ClassModule.from_module class_type, mod
1227
- klass.store = @store
1200
+ klass
1201
+ end
1228
1202
 
1229
- # if it was there, then we keep it even if done_documenting
1230
- @store.classes_hash[mod.full_name] = klass
1231
- enclosing.classes_hash[mod.name] = klass
1203
+ autoload :Section, "#{__dir__}/context/section"
1232
1204
 
1233
- klass
1234
1205
  end
1235
-
1236
- autoload :Section, "#{__dir__}/context/section"
1237
-
1238
1206
  end