@@ -325,10 +325,12 @@ def add_class class_type, given_name, superclass = '::Object'
325
325
name = full_name . split ( /:+/ ) . last
326
326
else
327
327
full_name = child_name given_name
328
+
328
329
if full_name =~ /^(.+)::(\w +)$/ then
329
330
name = $2
330
331
ename = $1
331
- enclosing = RDoc ::TopLevel . classes_hash [ ename ] || RDoc ::TopLevel . modules_hash [ ename ]
332
+ enclosing = RDoc ::TopLevel . classes_hash [ ename ] ||
333
+ RDoc ::TopLevel . modules_hash [ ename ]
332
334
# HACK: crashes in actionpack/lib/action_view/helpers/form_helper.rb (metaprogramming)
333
335
unless enclosing then
334
336
# try the given name at top level (will work for the above example)
@@ -338,7 +340,8 @@ def add_class class_type, given_name, superclass = '::Object'
338
340
names = ename . split ( '::' )
339
341
enclosing = self
340
342
names . each do |n |
341
- enclosing = enclosing . classes_hash [ n ] || enclosing . modules_hash [ n ] ||
343
+ enclosing = enclosing . classes_hash [ n ] ||
344
+ enclosing . modules_hash [ n ] ||
342
345
enclosing . add_module ( RDoc ::NormalModule , n )
343
346
end
344
347
end
@@ -363,18 +366,10 @@ def add_class class_type, given_name, superclass = '::Object'
363
366
end
364
367
end
365
368
366
- # did we believed it was a module?
367
- mod = RDoc ::TopLevel . modules_hash . delete ( superclass )
369
+ # did we believe it was a module?
370
+ mod = RDoc ::TopLevel . modules_hash . delete superclass
368
371
369
- if mod then
370
- super_context = mod . parent
371
- super_context . modules_hash . delete mod . name
372
- # TODO check: could it be RDoc::AnyClass?
373
- sklass = RDoc ::ClassModule . from_module ( RDoc ::NormalClass , mod )
374
- # if it was there, then we keep it even if mod.parent.done_documenting
375
- RDoc ::TopLevel . classes_hash [ sklass . full_name ] = sklass
376
- super_context . classes_hash [ sklass . name ] = sklass
377
- end
372
+ upgrade_to_class mod , RDoc ::NormalClass , mod . parent if mod
378
373
379
374
# e.g., Object < Object
380
375
superclass = nil if superclass == full_name
@@ -396,17 +391,15 @@ def add_class class_type, given_name, superclass = '::Object'
396
391
end
397
392
else
398
393
# this is a new class
399
- mod = RDoc ::TopLevel . modules_hash . delete ( full_name )
394
+ mod = RDoc ::TopLevel . modules_hash . delete full_name
395
+
400
396
if mod then
401
- # it was registered as a module, so transform it to a class
402
- enclosing . modules_hash . delete name
403
- klass = RDoc ::ClassModule . from_module ( class_type , mod )
397
+ klass = upgrade_to_class mod , RDoc ::NormalClass , enclosing
398
+
404
399
klass . superclass = superclass unless superclass . nil?
405
- # if it was there, then we keep it even if done_documenting
406
- RDoc ::TopLevel . classes_hash [ full_name ] = klass
407
- enclosing . classes_hash [ name ] = klass
408
400
else
409
- klass = class_type . new ( name , superclass )
401
+ klass = class_type . new name , superclass
402
+
410
403
enclosing . add_class_or_module ( klass , enclosing . classes_hash ,
411
404
RDoc ::TopLevel . classes_hash )
412
405
end
@@ -1027,5 +1020,20 @@ def top_level
1027
1020
@top_level
1028
1021
end
1029
1022
1023
+ ##
1024
+ # Upgrades NormalModule +mod+ in +enclosing+ to a +class_type+
1025
+
1026
+ def upgrade_to_class mod , class_type , enclosing
1027
+ enclosing . modules_hash . delete mod . name
1028
+
1029
+ klass = RDoc ::ClassModule . from_module class_type , mod
1030
+
1031
+ # if it was there, then we keep it even if done_documenting
1032
+ RDoc ::TopLevel . classes_hash [ full_name ] = klass
1033
+ enclosing . classes_hash [ name ] = klass
1034
+
1035
+ klass
1036
+ end
1037
+
1030
1038
end
1031
1039
0 commit comments