Skip to content

Commit 6c532d2

Browse files
committed
Remove nodoc items when storing a class or module
Since the document_self and ignored properties are not included in the store, items with these flags should also be removed from the output. This prevents the items from incorrectly showing up in the RDoc servlet or through ri. Fixes #177
1 parent e033904 commit 6c532d2

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

History.rdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
Bug #178 by Zachary Scott
2323
* RDoc no longer puts raw markup in HTML output for markdown input. Bug
2424
#204 by Erik Hollensbe
25+
* Code objects with nodoc are no longer included in the ri store. Bug #177
26+
by Thomas Leitner.
2527

2628
=== 4.0.0 / 2013-02-24
2729

lib/rdoc/class_module.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,18 @@ def full_name
282282

283283
def marshal_dump # :nodoc:
284284
attrs = attributes.sort.map do |attr|
285+
next unless attr.display?
285286
[ attr.name, attr.rw,
286287
attr.visibility, attr.singleton, attr.file_name,
287288
]
288-
end
289+
end.compact
289290

290291
method_types = methods_by_type.map do |type, visibilities|
291292
visibilities = visibilities.map do |visibility, methods|
292293
method_names = methods.map do |method|
294+
next unless method.display?
293295
[method.name, method.file_name]
294-
end
296+
end.compact
295297

296298
[visibility, method_names.uniq]
297299
end
@@ -305,14 +307,16 @@ def marshal_dump # :nodoc:
305307
@superclass,
306308
parse(@comment_location),
307309
attrs,
308-
constants,
310+
constants.select { |constant| constant.display? },
309311
includes.map do |incl|
312+
next unless incl.display?
310313
[incl.name, parse(incl.comment), incl.file_name]
311-
end,
314+
end.compact,
312315
method_types,
313316
extends.map do |ext|
317+
next unless ext.display?
314318
[ext.name, parse(ext.comment), ext.file_name]
315-
end,
319+
end.compact,
316320
@sections.values,
317321
@in_files.map do |tl|
318322
tl.relative_name

test/test_rdoc_class_module.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def test_marshal_dump
165165
ns = tl.add_module RDoc::NormalModule, 'Namespace'
166166

167167
cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super'
168+
cm.document_self = true
168169
cm.record_location tl
169170

170171
a1 = RDoc::Attr.new nil, 'a1', 'RW', ''
@@ -236,6 +237,66 @@ def test_marshal_dump
236237
assert_equal tl, loaded.method_list.first.file
237238
end
238239

240+
def test_marshal_dump_visibilty
241+
@store.path = Dir.tmpdir
242+
tl = @store.add_file 'file.rb'
243+
244+
ns = tl.add_module RDoc::NormalModule, 'Namespace'
245+
246+
cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super'
247+
cm.record_location tl
248+
249+
a1 = RDoc::Attr.new nil, 'a1', 'RW', ''
250+
a1.record_location tl
251+
a1.document_self = false
252+
253+
m1 = RDoc::AnyMethod.new nil, 'm1'
254+
m1.record_location tl
255+
m1.document_self = false
256+
257+
c1 = RDoc::Constant.new 'C1', nil, ''
258+
c1.record_location tl
259+
c1.document_self = false
260+
261+
i1 = RDoc::Include.new 'I1', ''
262+
i1.record_location tl
263+
i1.document_self = false
264+
265+
e1 = RDoc::Extend.new 'E1', ''
266+
e1.record_location tl
267+
e1.document_self = false
268+
269+
section_comment = RDoc::Comment.new('section comment')
270+
section_comment.location = tl
271+
272+
assert_equal 1, cm.sections.length, 'sanity, default section only'
273+
s0 = cm.sections.first
274+
s1 = cm.add_section 'section', section_comment
275+
276+
cm.add_attribute a1
277+
cm.add_method m1
278+
cm.add_constant c1
279+
cm.add_include i1
280+
cm.add_extend e1
281+
cm.add_comment 'this is a comment', tl
282+
283+
loaded = Marshal.load Marshal.dump cm
284+
loaded.store = @store
285+
286+
assert_equal cm, loaded
287+
288+
inner = RDoc::Markup::Document.new(
289+
RDoc::Markup::Paragraph.new('this is a comment'))
290+
inner.file = tl
291+
292+
comment = RDoc::Markup::Document.new inner
293+
294+
assert_empty loaded.attributes
295+
assert_empty loaded.constants
296+
assert_empty loaded.includes
297+
assert_empty loaded.extends
298+
assert_empty loaded.method_list
299+
end
239300
def test_marshal_load_version_0
240301
tl = @store.add_file 'file.rb'
241302
ns = tl.add_module RDoc::NormalModule, 'Namespace'

0 commit comments

Comments
 (0)