@@ -14,8 +14,13 @@ class RDoc::ClassModule < RDoc::Context
14
14
# 2::
15
15
# RDoc 3.13
16
16
# * Added extends
17
+ # 3::
18
+ # RDoc 4.0
19
+ # * Added sections
20
+ # * Added in_files
21
+ # * Added parent name
17
22
18
- MARSHAL_VERSION = 2 # :nodoc:
23
+ MARSHAL_VERSION = 3 # :nodoc:
19
24
20
25
##
21
26
# Constants that are aliases for this class or module
@@ -133,6 +138,17 @@ def add_comment comment, location
133
138
self . comment = original
134
139
end
135
140
141
+ def add_things my_things , other_things # :nodoc:
142
+ other_things . each do |group , things |
143
+ my_things [ group ] . each { |thing | yield false , thing } if
144
+ my_things . include? group
145
+
146
+ things . each do |thing |
147
+ yield true , thing
148
+ end
149
+ end
150
+ end
151
+
136
152
##
137
153
# Ancestors list for this ClassModule: the list of included modules
138
154
# (classes will add their superclass if any).
@@ -241,8 +257,8 @@ def find_class_named name
241
257
# Return the fully qualified name of this class or module
242
258
243
259
def full_name
244
- @full_name ||= if RDoc ::ClassModule === @ parent then
245
- "#{ @ parent. full_name } ::#{ @name } "
260
+ @full_name ||= if RDoc ::ClassModule === parent then
261
+ "#{ parent . full_name } ::#{ @name } "
246
262
else
247
263
@name
248
264
end
@@ -285,7 +301,13 @@ def marshal_dump # :nodoc:
285
301
method_types ,
286
302
extends . map do |ext |
287
303
[ ext . name , parse ( ext . comment ) , ext . file_name ]
288
- end
304
+ end ,
305
+ @sections . values ,
306
+ @in_files . map do |tl |
307
+ tl . absolute_name
308
+ end ,
309
+ parent . full_name ,
310
+ parent . class ,
289
311
]
290
312
end
291
313
@@ -297,6 +319,8 @@ def marshal_load array # :nodoc:
297
319
@parent = nil
298
320
@temporary_section = nil
299
321
@visibility = nil
322
+ @classes = { }
323
+ @modules = { }
300
324
301
325
@name = array [ 1 ]
302
326
@full_name = array [ 2 ]
@@ -347,6 +371,23 @@ def marshal_load array # :nodoc:
347
371
ext = add_extend RDoc ::Extend . new ( name , comment )
348
372
ext . record_location RDoc ::TopLevel . new file
349
373
end if array [ 9 ] # Support Marshal version 1
374
+
375
+ sections = ( array [ 10 ] || [ ] ) . map do |section |
376
+ [ section . title , section ]
377
+ end
378
+
379
+ @sections = Hash [ *sections . flatten ]
380
+
381
+ add_section nil
382
+
383
+ @in_files = [ ]
384
+
385
+ ( array [ 11 ] || [ ] ) . each do |filename |
386
+ record_location RDoc ::TopLevel . new filename
387
+ end
388
+
389
+ @parent_name = array [ 12 ]
390
+ @parent_class = array [ 13 ]
350
391
end
351
392
352
393
##
@@ -415,6 +456,8 @@ def merge class_module
415
456
end
416
457
end
417
458
459
+ merge_sections cm
460
+
418
461
self
419
462
end
420
463
@@ -437,22 +480,46 @@ def merge_collections mine, other, other_files, &block # :nodoc:
437
480
my_things = mine . group_by { |thing | thing . file }
438
481
other_things = other . group_by { |thing | thing . file }
439
482
440
- my_things . delete_if do |file , things |
441
- next false unless other_files . include? file
483
+ remove_things my_things , other_files , &block
484
+ add_things my_things , other_things , &block
485
+ end
442
486
443
- things . each do | thing |
444
- yield false , thing
445
- end
487
+ ##
488
+ # Merges the comments in this ClassModule with the comments in the other
489
+ # ClassModule +cm+.
446
490
447
- true
491
+ def merge_sections cm # :nodoc:
492
+ my_sections = sections . group_by { |section | section . title }
493
+ other_sections = cm . sections . group_by { |section | section . title }
494
+
495
+ other_files = cm . in_files
496
+
497
+ remove_things my_sections , other_files do |_ , section |
498
+ @sections . delete section . title
448
499
end
449
500
450
- other_things . each do |file , things |
451
- my_things [ file ] . each { |thing | yield false , thing } if
452
- my_things . include? ( file )
501
+ other_sections . each do |group , sections |
502
+ if my_sections . include? group
503
+ my_sections [ group ] . each do |my_section |
504
+ other_section = cm . sections_hash [ group ]
453
505
454
- things . each do |thing |
455
- yield true , thing
506
+ my_comments = my_section . comments
507
+ other_comments = other_section . comments
508
+
509
+ other_files = other_section . in_files
510
+
511
+ merge_collections my_comments , other_comments , other_files do |add , comment |
512
+ if add then
513
+ my_section . add_comment comment
514
+ else
515
+ my_section . remove_comment comment
516
+ end
517
+ end
518
+ end
519
+ else
520
+ sections . each do |section |
521
+ add_section group , section . comments
522
+ end
456
523
end
457
524
end
458
525
end
@@ -547,6 +614,18 @@ def remove_nodoc_children
547
614
end
548
615
end
549
616
617
+ def remove_things my_things , other_files # :nodoc:
618
+ my_things . delete_if do |file , things |
619
+ next false unless other_files . include? file
620
+
621
+ things . each do |thing |
622
+ yield false , thing
623
+ end
624
+
625
+ true
626
+ end
627
+ end
628
+
550
629
##
551
630
# Search record used by RDoc::Generator::JsonIndex
552
631
0 commit comments