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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -3
- data/RI.md +75 -75
- data/exe/rdoc +2 -2
- data/lib/rdoc/code_object/alias.rb +71 -69
- data/lib/rdoc/code_object/any_method.rb +305 -303
- data/lib/rdoc/code_object/attr.rb +150 -148
- data/lib/rdoc/code_object/class_module.rb +798 -792
- data/lib/rdoc/code_object/constant.rb +175 -173
- data/lib/rdoc/code_object/context/section.rb +142 -138
- data/lib/rdoc/code_object/context.rb +926 -958
- data/lib/rdoc/code_object/extend.rb +7 -5
- data/lib/rdoc/code_object/include.rb +7 -5
- data/lib/rdoc/code_object/method_attr.rb +326 -319
- data/lib/rdoc/code_object/mixin.rb +97 -95
- data/lib/rdoc/code_object/normal_class.rb +77 -78
- data/lib/rdoc/code_object/normal_module.rb +61 -59
- data/lib/rdoc/code_object/require.rb +23 -39
- data/lib/rdoc/code_object/single_class.rb +21 -19
- data/lib/rdoc/code_object/top_level.rb +212 -219
- data/lib/rdoc/code_object.rb +305 -303
- data/lib/rdoc/comment.rb +275 -273
- data/lib/rdoc/cross_reference.rb +192 -190
- data/lib/rdoc/encoding.rb +105 -103
- data/lib/rdoc/erb_partial.rb +13 -11
- data/lib/rdoc/erbio.rb +29 -27
- data/lib/rdoc/generator/aliki.rb +161 -153
- data/lib/rdoc/generator/darkfish.rb +645 -635
- data/lib/rdoc/generator/json_index.rb +233 -229
- data/lib/rdoc/generator/markup.rb +164 -146
- data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
- data/lib/rdoc/generator/pot/po.rb +52 -51
- data/lib/rdoc/generator/pot/po_entry.rb +138 -132
- data/lib/rdoc/generator/pot.rb +85 -81
- data/lib/rdoc/generator/ri.rb +23 -19
- data/lib/rdoc/generator/template/aliki/DESIGN.md +6 -4
- data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
- data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
- data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
- data/lib/rdoc/generator.rb +48 -46
- data/lib/rdoc/i18n/locale.rb +99 -95
- data/lib/rdoc/i18n/text.rb +109 -105
- data/lib/rdoc/i18n.rb +7 -5
- data/lib/rdoc/markdown/byte_runtime.rb +80 -0
- data/lib/rdoc/markdown.kpeg +15 -11
- data/lib/rdoc/markdown.rb +40 -47
- data/lib/rdoc/markup/block_quote.rb +12 -8
- data/lib/rdoc/markup/document.rb +127 -123
- data/lib/rdoc/markup/formatter.rb +219 -215
- data/lib/rdoc/markup/include.rb +33 -29
- data/lib/rdoc/markup/indented_paragraph.rb +37 -33
- data/lib/rdoc/markup/inline_parser.rb +281 -277
- data/lib/rdoc/markup/list.rb +80 -88
- data/lib/rdoc/markup/list_item.rb +73 -85
- data/lib/rdoc/markup/paragraph.rb +23 -19
- data/lib/rdoc/markup/parser.rb +501 -497
- data/lib/rdoc/markup/pre_process.rb +283 -279
- data/lib/rdoc/markup/raw.rb +2 -2
- data/lib/rdoc/markup/rule.rb +16 -12
- data/lib/rdoc/markup/to_ansi.rb +143 -139
- data/lib/rdoc/markup/to_bs.rb +72 -68
- data/lib/rdoc/markup/to_html.rb +594 -565
- data/lib/rdoc/markup/to_html_crossref.rb +234 -230
- data/lib/rdoc/markup/to_html_snippet.rb +232 -227
- data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
- data/lib/rdoc/markup/to_label.rb +63 -59
- data/lib/rdoc/markup/to_markdown.rb +212 -208
- data/lib/rdoc/markup/to_rdoc.rb +336 -332
- data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
- data/lib/rdoc/markup/to_test.rb +60 -56
- data/lib/rdoc/markup/to_tt_only.rb +84 -80
- data/lib/rdoc/markup/verbatim.rb +62 -58
- data/lib/rdoc/markup.rb +198 -196
- data/lib/rdoc/options.rb +1063 -1061
- data/lib/rdoc/parser/c.rb +1039 -1037
- data/lib/rdoc/parser/changelog.rb +319 -315
- data/lib/rdoc/parser/markdown.rb +17 -13
- data/lib/rdoc/parser/rbs.rb +239 -235
- data/lib/rdoc/parser/rd.rb +17 -13
- data/lib/rdoc/parser/ruby.rb +1245 -1124
- data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
- data/lib/rdoc/parser/simple.rb +31 -27
- data/lib/rdoc/parser/text.rb +12 -8
- data/lib/rdoc/parser.rb +228 -220
- data/lib/rdoc/rbs_helper.rb +1 -1
- data/lib/rdoc/rd/inline.rb +57 -53
- data/lib/rdoc/rd.rb +90 -88
- data/lib/rdoc/rdoc.rb +500 -491
- data/lib/rdoc/ri/driver.rb +1140 -1135
- data/lib/rdoc/ri/formatter.rb +7 -3
- data/lib/rdoc/ri/paths.rb +140 -136
- data/lib/rdoc/ri/servlet.rb +354 -350
- data/lib/rdoc/ri/store.rb +4 -2
- data/lib/rdoc/ri/task.rb +55 -51
- data/lib/rdoc/ri.rb +14 -12
- data/lib/rdoc/rubygems_hook.rb +183 -181
- data/lib/rdoc/server.rb +349 -347
- data/lib/rdoc/stats/normal.rb +46 -42
- data/lib/rdoc/stats/quiet.rb +39 -35
- data/lib/rdoc/stats/verbose.rb +35 -31
- data/lib/rdoc/stats.rb +365 -363
- data/lib/rdoc/store.rb +888 -902
- data/lib/rdoc/task.rb +260 -256
- data/lib/rdoc/text.rb +135 -133
- data/lib/rdoc/token_stream.rb +101 -93
- data/lib/rdoc/tom_doc.rb +203 -201
- data/lib/rdoc/version.rb +1 -1
- metadata +4 -5
- data/lib/rdoc/markdown/literals.kpeg +0 -21
- 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
|
-
#
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
12
|
+
##
|
|
13
|
+
# Types of methods
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
# Class/module aliases
|
|
15
|
+
TYPES = %w[class instance]
|
|
24
16
|
|
|
25
|
-
|
|
17
|
+
##
|
|
18
|
+
# If a context has these titles it will be sorted in this order.
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
TOMDOC_TITLES = [nil, 'Public', 'Internal', 'Deprecated'] # :nodoc:
|
|
21
|
+
TOMDOC_TITLES_SORT = TOMDOC_TITLES.sort_by { |title| title.to_s } # :nodoc:
|
|
29
22
|
|
|
30
|
-
|
|
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
|
-
|
|
28
|
+
##
|
|
29
|
+
# All attr* methods
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
# Constants defined
|
|
31
|
+
attr_reader :attributes
|
|
39
32
|
|
|
40
|
-
|
|
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
|
-
|
|
38
|
+
##
|
|
39
|
+
# Constants defined
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
# Files this context is found in
|
|
41
|
+
attr_reader :constants
|
|
49
42
|
|
|
50
|
-
|
|
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
|
-
|
|
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
|
-
|
|
53
|
+
##
|
|
54
|
+
# Modules this context includes
|
|
69
55
|
|
|
70
|
-
|
|
56
|
+
attr_reader :includes
|
|
71
57
|
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
##
|
|
59
|
+
# Modules this context is extended with
|
|
74
60
|
|
|
75
|
-
|
|
61
|
+
attr_reader :extends
|
|
76
62
|
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
##
|
|
64
|
+
# Methods defined in this context
|
|
79
65
|
|
|
80
|
-
|
|
66
|
+
attr_reader :method_list
|
|
81
67
|
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
71
|
+
attr_reader :name
|
|
88
72
|
|
|
89
|
-
|
|
90
|
-
|
|
73
|
+
##
|
|
74
|
+
# Files this context requires
|
|
91
75
|
|
|
92
|
-
|
|
76
|
+
attr_reader :requires
|
|
93
77
|
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
##
|
|
79
|
+
# Use this section for the next method, attribute or constant added.
|
|
96
80
|
|
|
97
|
-
|
|
81
|
+
attr_accessor :temporary_section
|
|
98
82
|
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
88
|
+
attr_accessor :unmatched_alias_lists
|
|
103
89
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
# twice if they are RW.
|
|
90
|
+
##
|
|
91
|
+
# Aliases that could not be resolved.
|
|
107
92
|
|
|
108
|
-
|
|
93
|
+
attr_reader :external_aliases
|
|
109
94
|
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
##
|
|
96
|
+
# Hash of registered methods. Attributes are also registered here,
|
|
97
|
+
# twice if they are RW.
|
|
112
98
|
|
|
113
|
-
|
|
99
|
+
attr_reader :methods_hash
|
|
114
100
|
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
##
|
|
102
|
+
# Params to be used in the next MethodAttr parsed under this context
|
|
117
103
|
|
|
118
|
-
|
|
104
|
+
attr_accessor :params
|
|
119
105
|
|
|
120
|
-
|
|
121
|
-
|
|
106
|
+
##
|
|
107
|
+
# Hash of registered constants.
|
|
122
108
|
|
|
123
|
-
|
|
124
|
-
super
|
|
109
|
+
attr_reader :constants_hash
|
|
125
110
|
|
|
126
|
-
|
|
111
|
+
##
|
|
112
|
+
# Creates an unnamed empty context
|
|
127
113
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
@visibility = :public
|
|
114
|
+
def initialize
|
|
115
|
+
super
|
|
131
116
|
|
|
132
|
-
|
|
133
|
-
@sections = { nil => @current_section }
|
|
134
|
-
@temporary_section = nil
|
|
117
|
+
@in_files = []
|
|
135
118
|
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
140
|
-
|
|
125
|
+
@classes = {}
|
|
126
|
+
@modules = {}
|
|
141
127
|
|
|
142
|
-
|
|
143
|
-
|
|
128
|
+
initialize_methods_etc
|
|
129
|
+
end
|
|
144
130
|
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
161
|
-
|
|
147
|
+
@methods_hash = {}
|
|
148
|
+
@constants_hash = {}
|
|
162
149
|
|
|
163
|
-
|
|
150
|
+
@params = nil
|
|
164
151
|
|
|
165
|
-
|
|
166
|
-
|
|
152
|
+
@store ||= nil
|
|
153
|
+
end
|
|
167
154
|
|
|
168
|
-
|
|
169
|
-
|
|
155
|
+
##
|
|
156
|
+
# Contexts are sorted by full_name
|
|
170
157
|
|
|
171
|
-
|
|
172
|
-
|
|
158
|
+
def <=>(other)
|
|
159
|
+
return nil unless CodeObject === other
|
|
173
160
|
|
|
174
|
-
|
|
175
|
-
|
|
161
|
+
full_name <=> other.full_name
|
|
162
|
+
end
|
|
176
163
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
182
|
+
##
|
|
183
|
+
# Adds +an_alias+ that is automatically resolved
|
|
197
184
|
|
|
198
|
-
|
|
199
|
-
|
|
185
|
+
def add_alias(an_alias)
|
|
186
|
+
return an_alias unless @document_self
|
|
200
187
|
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
214
|
-
|
|
200
|
+
an_alias
|
|
201
|
+
end
|
|
215
202
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
226
|
-
|
|
212
|
+
def add_attribute(attribute)
|
|
213
|
+
return attribute unless @document_self
|
|
227
214
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
219
|
+
key = nil
|
|
233
220
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
221
|
+
if attribute.rw.index 'R'
|
|
222
|
+
key = attribute.pretty_name
|
|
223
|
+
known = @methods_hash[key]
|
|
237
224
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
236
|
+
if attribute.rw.index 'W'
|
|
237
|
+
key = attribute.pretty_name + '='
|
|
238
|
+
known = @methods_hash[key]
|
|
252
239
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
end
|
|
251
|
+
if register
|
|
252
|
+
add_to @attributes, attribute
|
|
253
|
+
resolve_aliases attribute
|
|
254
|
+
end
|
|
269
255
|
|
|
270
|
-
|
|
271
|
-
|
|
256
|
+
attribute
|
|
257
|
+
end
|
|
272
258
|
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
#
|
|
295
|
-
#
|
|
296
|
-
|
|
297
|
-
#
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
320
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
342
|
-
|
|
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
|
-
|
|
347
|
-
|
|
332
|
+
# did we believe it was a module?
|
|
333
|
+
mod = @store.modules_hash.delete superclass
|
|
348
334
|
|
|
349
|
-
|
|
335
|
+
upgrade_to_class mod, NormalClass, mod.parent if mod
|
|
350
336
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
337
|
+
# e.g., Object < Object
|
|
338
|
+
superclass = nil if superclass == full_name
|
|
339
|
+
end
|
|
354
340
|
|
|
355
|
-
|
|
341
|
+
klass = @store.classes_hash[full_name]
|
|
356
342
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
343
|
+
if klass
|
|
344
|
+
# if TopLevel, it may not be registered in the classes:
|
|
345
|
+
enclosing.classes_hash[name] = klass
|
|
360
346
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
|
|
375
|
-
|
|
360
|
+
if mod
|
|
361
|
+
klass = upgrade_to_class mod, NormalClass, enclosing
|
|
376
362
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
363
|
+
klass.superclass = superclass unless superclass.nil?
|
|
364
|
+
else
|
|
365
|
+
klass = class_type.new name, superclass
|
|
380
366
|
|
|
381
|
-
|
|
382
|
-
|
|
367
|
+
enclosing.add_class_or_module(klass, enclosing.classes_hash,
|
|
368
|
+
@store.classes_hash)
|
|
369
|
+
end
|
|
383
370
|
end
|
|
384
|
-
end
|
|
385
371
|
|
|
386
|
-
|
|
372
|
+
klass.parent = self
|
|
387
373
|
|
|
388
|
-
|
|
389
|
-
|
|
374
|
+
klass
|
|
375
|
+
end
|
|
390
376
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
417
|
-
|
|
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
|
-
|
|
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
|
-
|
|
424
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
known = @constants_hash[constant.name]
|
|
412
|
+
if known
|
|
413
|
+
known.comment = constant.comment if known.comment.empty?
|
|
429
414
|
|
|
430
|
-
|
|
431
|
-
|
|
415
|
+
known.value = constant.value if
|
|
416
|
+
known.value.nil? or known.value.strip.empty?
|
|
432
417
|
|
|
433
|
-
|
|
434
|
-
known.
|
|
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
|
|
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
|
-
|
|
444
|
-
|
|
428
|
+
##
|
|
429
|
+
# Adds included module +include+ which should be an RDoc::Include
|
|
445
430
|
|
|
446
|
-
|
|
447
|
-
|
|
431
|
+
def add_include(include)
|
|
432
|
+
add_to @includes, include
|
|
448
433
|
|
|
449
|
-
|
|
450
|
-
|
|
434
|
+
include
|
|
435
|
+
end
|
|
451
436
|
|
|
452
|
-
|
|
453
|
-
|
|
437
|
+
##
|
|
438
|
+
# Adds extension module +ext+ which should be an RDoc::Extend
|
|
454
439
|
|
|
455
|
-
|
|
456
|
-
|
|
440
|
+
def add_extend(ext)
|
|
441
|
+
add_to @extends, ext
|
|
457
442
|
|
|
458
|
-
|
|
459
|
-
|
|
443
|
+
ext
|
|
444
|
+
end
|
|
460
445
|
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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
|
-
|
|
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
|
-
|
|
495
|
-
|
|
471
|
+
method
|
|
472
|
+
end
|
|
496
473
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
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
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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
|
-
|
|
509
|
-
|
|
485
|
+
owner_path, separator, name = constant_path.rpartition('::')
|
|
486
|
+
owner = owner.find_or_create_namespace_path owner_path unless separator.empty?
|
|
510
487
|
|
|
511
|
-
|
|
512
|
-
|
|
488
|
+
[owner, name]
|
|
489
|
+
end
|
|
513
490
|
|
|
514
|
-
|
|
515
|
-
|
|
491
|
+
##
|
|
492
|
+
# Finds or creates the module namespace path under this context.
|
|
516
493
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
-
|
|
527
|
-
|
|
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
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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
|
-
|
|
536
|
-
|
|
512
|
+
mod = @classes[name] || @modules[name]
|
|
513
|
+
return mod if mod
|
|
537
514
|
|
|
538
|
-
|
|
539
|
-
|
|
515
|
+
full_name = child_name name
|
|
516
|
+
mod = @store.modules_hash[full_name] || class_type.new(name)
|
|
540
517
|
|
|
541
|
-
|
|
542
|
-
|
|
518
|
+
add_class_or_module mod, @modules, @store.modules_hash
|
|
519
|
+
end
|
|
543
520
|
|
|
544
|
-
|
|
545
|
-
|
|
521
|
+
##
|
|
522
|
+
# Adds a module by +RDoc::NormalModule+ instance. See also #add_module.
|
|
546
523
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
524
|
+
def add_module_by_normal_module(mod)
|
|
525
|
+
add_class_or_module mod, @modules, @store.modules_hash
|
|
526
|
+
end
|
|
550
527
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
528
|
+
##
|
|
529
|
+
# Adds an alias from +from+ (a class or module) to the constant +to+ which
|
|
530
|
+
# was defined in +file+.
|
|
554
531
|
|
|
555
|
-
|
|
556
|
-
|
|
532
|
+
def add_module_alias(from, to, file)
|
|
533
|
+
return from if @done_documenting
|
|
557
534
|
|
|
558
|
-
|
|
535
|
+
to_full_name = child_name to.name
|
|
559
536
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
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
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
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
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
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
|
-
|
|
585
|
-
#
|
|
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
|
-
|
|
592
|
-
|
|
569
|
+
def add_require(require)
|
|
570
|
+
return require unless @document_self
|
|
593
571
|
|
|
594
|
-
|
|
595
|
-
|
|
572
|
+
if TopLevel === self
|
|
573
|
+
add_to @requires, require
|
|
574
|
+
else
|
|
575
|
+
parent.add_require require
|
|
576
|
+
end
|
|
577
|
+
end
|
|
596
578
|
|
|
597
|
-
|
|
598
|
-
|
|
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
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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
|
-
|
|
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
|
-
|
|
601
|
+
def add_to(array, thing)
|
|
602
|
+
array << thing if @document_self
|
|
628
603
|
|
|
629
|
-
|
|
630
|
-
|
|
604
|
+
thing.parent = self
|
|
605
|
+
thing.store = @store if @store
|
|
606
|
+
thing.section = current_section
|
|
607
|
+
end
|
|
631
608
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
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
|
-
|
|
650
|
+
##
|
|
651
|
+
# Array of classes in this context
|
|
673
652
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
653
|
+
def classes
|
|
654
|
+
@classes.values
|
|
655
|
+
end
|
|
677
656
|
|
|
678
|
-
|
|
679
|
-
|
|
657
|
+
##
|
|
658
|
+
# All classes and modules in this namespace
|
|
680
659
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
660
|
+
def classes_and_modules
|
|
661
|
+
classes + modules
|
|
662
|
+
end
|
|
684
663
|
|
|
685
|
-
|
|
686
|
-
|
|
664
|
+
##
|
|
665
|
+
# Hash of classes keyed by class name
|
|
687
666
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
667
|
+
def classes_hash
|
|
668
|
+
@classes
|
|
669
|
+
end
|
|
691
670
|
|
|
692
|
-
|
|
693
|
-
|
|
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
|
-
|
|
696
|
-
|
|
697
|
-
|
|
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
|
-
|
|
701
|
-
# temporary_section is available it will be used.
|
|
682
|
+
section
|
|
683
|
+
end
|
|
702
684
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
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
|
-
|
|
711
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
729
|
-
|
|
706
|
+
def each_classmodule(&block) # :yields: module
|
|
707
|
+
classes_and_modules.sort.each(&block)
|
|
708
|
+
end
|
|
730
709
|
|
|
731
|
-
|
|
732
|
-
|
|
710
|
+
##
|
|
711
|
+
# Iterator for methods
|
|
733
712
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
end
|
|
713
|
+
def each_method # :yields: method
|
|
714
|
+
return enum_for __method__ unless block_given?
|
|
737
715
|
|
|
738
|
-
|
|
739
|
-
|
|
716
|
+
@method_list.sort.each { |m| yield m }
|
|
717
|
+
end
|
|
740
718
|
|
|
741
|
-
|
|
742
|
-
|
|
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
|
-
|
|
745
|
-
|
|
729
|
+
def each_section # :yields: section, constants, attributes
|
|
730
|
+
return enum_for __method__ unless block_given?
|
|
746
731
|
|
|
747
|
-
|
|
748
|
-
|
|
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
|
-
|
|
758
|
-
|
|
735
|
+
constants.default = []
|
|
736
|
+
attributes.default = []
|
|
759
737
|
|
|
760
|
-
|
|
761
|
-
|
|
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
|
-
|
|
764
|
-
|
|
743
|
+
##
|
|
744
|
+
# Finds an attribute +name+ with singleton value +singleton+.
|
|
765
745
|
|
|
766
|
-
|
|
767
|
-
|
|
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
|
-
|
|
751
|
+
##
|
|
752
|
+
# Finds an attribute with +name+ in this context
|
|
773
753
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
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
|
-
|
|
765
|
+
##
|
|
766
|
+
# Finds a class method with +name+ in this context
|
|
781
767
|
|
|
782
|
-
|
|
783
|
-
|
|
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
|
-
|
|
772
|
+
##
|
|
773
|
+
# Finds a constant with +name+ in this context
|
|
795
774
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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
|
-
|
|
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
|
-
|
|
804
|
-
|
|
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
|
-
|
|
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
|
-
|
|
816
|
-
|
|
817
|
-
|
|
794
|
+
def find_external_alias(name, singleton)
|
|
795
|
+
@external_aliases.find { |m| m.name == name && m.singleton == singleton }
|
|
796
|
+
end
|
|
818
797
|
|
|
819
|
-
|
|
820
|
-
|
|
798
|
+
##
|
|
799
|
+
# Finds an external alias with +name+ in this context
|
|
821
800
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
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
|
-
|
|
812
|
+
##
|
|
813
|
+
# Finds an instance method with +name+ in this context
|
|
828
814
|
|
|
829
|
-
|
|
830
|
-
|
|
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
|
-
|
|
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
|
-
|
|
844
|
-
|
|
845
|
-
end
|
|
832
|
+
##
|
|
833
|
+
# Finds a method named +name+ with singleton value +singleton+.
|
|
846
834
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
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
|
-
|
|
845
|
+
##
|
|
846
|
+
# Finds a instance or module method with +name+ in this context
|
|
862
847
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
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
|
-
|
|
855
|
+
@method_list.find { |meth| meth.name == name }
|
|
869
856
|
end
|
|
870
|
-
|
|
871
|
-
end
|
|
857
|
+
end
|
|
872
858
|
|
|
873
|
-
|
|
874
|
-
|
|
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
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
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
|
-
|
|
899
|
-
|
|
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
|
-
|
|
902
|
-
|
|
903
|
-
|
|
873
|
+
def get_module_named(name)
|
|
874
|
+
@modules[name] || @classes[name]
|
|
875
|
+
end
|
|
904
876
|
|
|
905
|
-
|
|
906
|
-
|
|
877
|
+
##
|
|
878
|
+
# Look up +symbol+, first as a module, then as a local symbol.
|
|
907
879
|
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
880
|
+
def find_symbol(symbol)
|
|
881
|
+
find_symbol_module(symbol) || find_local_symbol(symbol)
|
|
882
|
+
end
|
|
911
883
|
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
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
|
-
|
|
943
|
-
|
|
917
|
+
##
|
|
918
|
+
# The full name for this context. This method is overridden by subclasses.
|
|
944
919
|
|
|
945
|
-
|
|
946
|
-
|
|
920
|
+
def full_name
|
|
921
|
+
'(unknown)'
|
|
922
|
+
end
|
|
947
923
|
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
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
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
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
|
-
|
|
936
|
+
##
|
|
937
|
+
# URL for this with a +prefix+
|
|
966
938
|
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
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
|
-
|
|
973
|
-
|
|
944
|
+
File.join(*path.compact) + '.html'
|
|
945
|
+
end
|
|
974
946
|
|
|
975
|
-
|
|
976
|
-
|
|
947
|
+
##
|
|
948
|
+
# Instance methods
|
|
977
949
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
950
|
+
def instance_methods
|
|
951
|
+
method_list.reject { |a| a.singleton }
|
|
952
|
+
end
|
|
981
953
|
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
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
|
-
|
|
999
|
-
|
|
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
|
-
|
|
1002
|
-
next if section and not method.section == section
|
|
1003
|
-
methods[method.type][method.visibility] << method
|
|
978
|
+
methods
|
|
1004
979
|
end
|
|
1005
980
|
|
|
1006
|
-
|
|
1007
|
-
|
|
981
|
+
##
|
|
982
|
+
# Yields AnyMethod and Attr entries matching the list of names in +methods+.
|
|
1008
983
|
|
|
1009
|
-
|
|
1010
|
-
|
|
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
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
989
|
+
each_ancestor do |parent|
|
|
990
|
+
parent.methods_matching(methods, singleton, &block)
|
|
991
|
+
end
|
|
1015
992
|
end
|
|
1016
993
|
|
|
1017
|
-
|
|
1018
|
-
|
|
994
|
+
##
|
|
995
|
+
# Array of modules in this context
|
|
996
|
+
|
|
997
|
+
def modules
|
|
998
|
+
@modules.values
|
|
1019
999
|
end
|
|
1020
|
-
end
|
|
1021
1000
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1001
|
+
##
|
|
1002
|
+
# Hash of modules keyed by module name
|
|
1024
1003
|
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1004
|
+
def modules_hash
|
|
1005
|
+
@modules
|
|
1006
|
+
end
|
|
1028
1007
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1008
|
+
##
|
|
1009
|
+
# Name to use to generate the url.
|
|
1010
|
+
# <tt>#full_name</tt> by default.
|
|
1031
1011
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1012
|
+
def name_for_path
|
|
1013
|
+
full_name
|
|
1014
|
+
end
|
|
1035
1015
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
# <tt>#full_name</tt> by default.
|
|
1016
|
+
##
|
|
1017
|
+
# Record +top_level+ as a file +self+ is in.
|
|
1039
1018
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1019
|
+
def record_location(top_level)
|
|
1020
|
+
@in_files << top_level unless @in_files.include?(top_level)
|
|
1021
|
+
end
|
|
1043
1022
|
|
|
1044
|
-
|
|
1045
|
-
|
|
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
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1055
|
-
|
|
1056
|
-
end
|
|
1055
|
+
##
|
|
1056
|
+
# Only called when min_visibility == :public or :private
|
|
1057
1057
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
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
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
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
|
-
|
|
1086
|
+
##
|
|
1087
|
+
# Returns RDoc::Context::Section objects referenced in this context for use
|
|
1088
|
+
# in a table of contents.
|
|
1090
1089
|
|
|
1091
|
-
|
|
1092
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1121
|
-
# in a table of contents.
|
|
1096
|
+
used_sections[method.section] = true
|
|
1097
|
+
end
|
|
1122
1098
|
|
|
1123
|
-
|
|
1124
|
-
|
|
1099
|
+
# order found sections
|
|
1100
|
+
sections = sort_sections.select do |section|
|
|
1101
|
+
used_sections[section]
|
|
1102
|
+
end
|
|
1125
1103
|
|
|
1126
|
-
|
|
1127
|
-
|
|
1104
|
+
# only the default section is used
|
|
1105
|
+
return [] if
|
|
1106
|
+
sections.length == 1 and not sections.first.title
|
|
1128
1107
|
|
|
1129
|
-
|
|
1108
|
+
sections
|
|
1130
1109
|
end
|
|
1131
1110
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1111
|
+
##
|
|
1112
|
+
# Sections in this context
|
|
1113
|
+
|
|
1114
|
+
def sections
|
|
1115
|
+
@sections.values
|
|
1135
1116
|
end
|
|
1136
1117
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1118
|
+
def sections_hash # :nodoc:
|
|
1119
|
+
@sections
|
|
1120
|
+
end
|
|
1140
1121
|
|
|
1141
|
-
|
|
1142
|
-
|
|
1122
|
+
##
|
|
1123
|
+
# Sets the current section to a section with +title+. See also #add_section
|
|
1143
1124
|
|
|
1144
|
-
|
|
1145
|
-
|
|
1125
|
+
def set_current_section(title, comment)
|
|
1126
|
+
@current_section = add_section title, comment
|
|
1127
|
+
end
|
|
1146
1128
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1129
|
+
##
|
|
1130
|
+
# Given an array +methods+ of method names, set the visibility of each to
|
|
1131
|
+
# +visibility+
|
|
1150
1132
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
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
|
-
|
|
1139
|
+
##
|
|
1140
|
+
# Given an array +names+ of constants, set the visibility of each constant to
|
|
1141
|
+
# +visibility+
|
|
1157
1142
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
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
|
-
|
|
1164
|
-
|
|
1150
|
+
##
|
|
1151
|
+
# Sorts sections alphabetically (default) or in TomDoc fashion (none,
|
|
1152
|
+
# Public, Internal, Deprecated)
|
|
1165
1153
|
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
m.visibility = visibility
|
|
1169
|
-
end
|
|
1170
|
-
end
|
|
1154
|
+
def sort_sections
|
|
1155
|
+
titles = @sections.map { |title, _| title }
|
|
1171
1156
|
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
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
|
-
|
|
1177
|
-
|
|
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
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
@
|
|
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
|
-
|
|
1204
|
-
|
|
1205
|
-
end
|
|
1187
|
+
##
|
|
1188
|
+
# Upgrades NormalModule +mod+ in +enclosing+ to a +class_type+
|
|
1206
1189
|
|
|
1207
|
-
|
|
1208
|
-
|
|
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
|
-
|
|
1193
|
+
klass = ClassModule.from_module class_type, mod
|
|
1194
|
+
klass.store = @store
|
|
1222
1195
|
|
|
1223
|
-
|
|
1224
|
-
|
|
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
|
-
|
|
1227
|
-
|
|
1200
|
+
klass
|
|
1201
|
+
end
|
|
1228
1202
|
|
|
1229
|
-
|
|
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
|