Skip to content

Commit c809ba8

Browse files
authored
Avoid accessing RDoc objects through Store (#1308)
There's an unhealthy coupling between `RDoc` and `Store`, where they hold reference of each other and access things both ways. IMO, `RDoc` instances holding `Store` objects makes sense as `Store` is a component of it. But `Store` shouldn't need to reference back to its `RDoc` instance. This PR is the first step of removing this coupling by dropping `Store#rdoc` usages.
1 parent 49f72ac commit c809ba8

File tree

9 files changed

+19
-28
lines changed

9 files changed

+19
-28
lines changed

lib/rdoc/code_object.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,7 @@ def ignored?
300300
# This is used by Text#snippet
301301

302302
def options
303-
if @store and @store.rdoc then
304-
@store.rdoc.options
305-
else
306-
RDoc::Options.new
307-
end
303+
@store&.options || RDoc::Options.new
308304
end
309305

310306
##

lib/rdoc/code_object/context.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def add_method method
482482
known.comment = method.comment if known.comment.empty?
483483
previously = ", previously in #{known.file}" unless
484484
method.file == known.file
485-
@store.rdoc.options.warn \
485+
@store.options.warn \
486486
"Duplicate method #{known.full_name} in #{method.file}#{previously}"
487487
end
488488
else

lib/rdoc/generator/markup.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def description
3434
def formatter
3535
return @formatter if defined? @formatter
3636

37-
options = @store.rdoc.options
37+
options = @store.options
3838
this = RDoc::Context === self ? self : @parent
3939

4040
@formatter = RDoc::Markup::ToHtmlCrossref.new options, this.path, this
@@ -147,7 +147,7 @@ class RDoc::TopLevel
147147
# command line option to set.
148148

149149
def cvs_url
150-
url = @store.rdoc.options.webcvs
150+
url = @store.options.webcvs
151151

152152
if /%s/ =~ url then
153153
url % @relative_name

lib/rdoc/store.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ def message # :nodoc:
9494

9595
attr_accessor :path
9696

97-
##
98-
# The RDoc::RDoc driver for this parse tree. This allows classes consulting
99-
# the documentation tree to access user-set options, for example.
100-
101-
attr_accessor :rdoc
97+
attr_writer :rdoc
10298

10399
##
104100
# Type of ri datastore this was loaded from. See RDoc::RI::Driver,
@@ -981,6 +977,10 @@ def unique_modules
981977
@unique_modules
982978
end
983979

980+
def options
981+
@rdoc&.options
982+
end
983+
984984
private
985985
def marshal_load(file)
986986
File.open(file, 'rb') {|io| Marshal.load(io, MarshalFilter)}

lib/rdoc/text.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def flush_left text
9999
# Requires the including class to implement #formatter
100100

101101
def markup text
102-
if @store.rdoc.options
103-
locale = @store.rdoc.options.locale
102+
if @store.options
103+
locale = @store.options.locale
104104
else
105105
locale = nil
106106
end

test/rdoc/test_rdoc_code_object.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_document_children_equals
122122

123123
refute @co.document_children
124124

125-
@store.rdoc.options.visibility = :nodoc
125+
@store.options.visibility = :nodoc
126126

127127
@co.store = @store
128128

@@ -137,7 +137,7 @@ def test_document_self_equals
137137
@co.document_self = false
138138
refute @co.document_self
139139

140-
@store.rdoc.options.visibility = :nodoc
140+
@store.options.visibility = :nodoc
141141

142142
@co.store = @store
143143

@@ -190,7 +190,7 @@ def test_done_documenting
190190

191191
@co.done_documenting = true
192192

193-
@store.rdoc.options.visibility = :nodoc
193+
@store.options.visibility = :nodoc
194194

195195
@co.store = @store
196196

@@ -236,7 +236,7 @@ def test_ignore
236236
refute @co.document_children
237237
assert @co.ignored?
238238

239-
@store.rdoc.options.visibility = :nodoc
239+
@store.options.visibility = :nodoc
240240

241241
@co.store = @store
242242

@@ -381,7 +381,7 @@ def test_store_equals
381381

382382
refute @co.document_self
383383

384-
@store.rdoc.options.visibility = :nodoc
384+
@store.options.visibility = :nodoc
385385

386386
@co.store = @store
387387

@@ -397,7 +397,7 @@ def test_stop_doc
397397
refute @co.document_self
398398
refute @co.document_children
399399

400-
@store.rdoc.options.visibility = :nodoc
400+
@store.options.visibility = :nodoc
401401

402402
@co.store = @store
403403

@@ -417,7 +417,7 @@ def test_suppress
417417
refute @co.document_children
418418
assert @co.suppressed?
419419

420-
@store.rdoc.options.visibility = :nodoc
420+
@store.options.visibility = :nodoc
421421

422422
@co.store = @store
423423

test/rdoc/test_rdoc_context.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def test_add_method_alias
219219
end
220220

221221
def test_add_method_duplicate
222-
@store.rdoc.options.verbosity = 2
222+
@store.options.verbosity = 2
223223

224224
meth1 = RDoc::AnyMethod.new nil, 'name'
225225
meth1.record_location @store.add_file 'first.rb'

test/rdoc/test_rdoc_rdoc.rb

-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def test_document # functional test
3131
end
3232

3333
assert File.directory? 'ri'
34-
assert_equal rdoc, rdoc.store.rdoc
3534
end
3635

3736
store = rdoc.store
@@ -58,7 +57,6 @@ def test_document_with_dry_run # functional test
5857
end
5958

6059
refute File.directory? 'doc'
61-
assert_equal rdoc, rdoc.store.rdoc
6260
end
6361
assert_includes out, '100%'
6462

test/rdoc/test_rdoc_servlet.rb

-3
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@ def test_generator_for
294294

295295
assert_equal 'MAIN_PAGE.rdoc', @s.options.main_page
296296
assert_equal 'Title', @s.options.title
297-
298-
assert_kind_of RDoc::RDoc, store.rdoc
299-
assert_same generator, store.rdoc.generator
300297
end
301298

302299
def test_if_modified_since

0 commit comments

Comments
 (0)