Skip to content

Avoid accessing RDoc objects through Store #1308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/rdoc/code_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,7 @@ def ignored?
# This is used by Text#snippet

def options
if @store and @store.rdoc then
@store.rdoc.options
else
RDoc::Options.new
end
@store&.options || RDoc::Options.new
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/code_object/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def add_method method
known.comment = method.comment if known.comment.empty?
previously = ", previously in #{known.file}" unless
method.file == known.file
@store.rdoc.options.warn \
@store.options.warn \
"Duplicate method #{known.full_name} in #{method.file}#{previously}"
end
else
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/generator/markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def description
def formatter
return @formatter if defined? @formatter

options = @store.rdoc.options
options = @store.options
this = RDoc::Context === self ? self : @parent

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

def cvs_url
url = @store.rdoc.options.webcvs
url = @store.options.webcvs

if /%s/ =~ url then
url % @relative_name
Expand Down
10 changes: 5 additions & 5 deletions lib/rdoc/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ def message # :nodoc:

attr_accessor :path

##
# The RDoc::RDoc driver for this parse tree. This allows classes consulting
# the documentation tree to access user-set options, for example.

attr_accessor :rdoc
attr_writer :rdoc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think RDoc::Store only needs attr_accessor :options, but we need to consider the initialization order of rdoc.options and store.rdoc. Maybe we can do it in another followup pull request later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a WIP PR for that (which was meant to be part of this PR). I still have a few tests to fix but can open a draft for it after this is merged.


##
# Type of ri datastore this was loaded from. See RDoc::RI::Driver,
Expand Down Expand Up @@ -981,6 +977,10 @@ def unique_modules
@unique_modules
end

def options
@rdoc&.options
end

private
def marshal_load(file)
File.open(file, 'rb') {|io| Marshal.load(io, MarshalFilter)}
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def flush_left text
# Requires the including class to implement #formatter

def markup text
if @store.rdoc.options
locale = @store.rdoc.options.locale
if @store.options
locale = @store.options.locale
else
locale = nil
end
Expand Down
14 changes: 7 additions & 7 deletions test/rdoc/test_rdoc_code_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_document_children_equals

refute @co.document_children

@store.rdoc.options.visibility = :nodoc
@store.options.visibility = :nodoc

@co.store = @store

Expand All @@ -137,7 +137,7 @@ def test_document_self_equals
@co.document_self = false
refute @co.document_self

@store.rdoc.options.visibility = :nodoc
@store.options.visibility = :nodoc

@co.store = @store

Expand Down Expand Up @@ -190,7 +190,7 @@ def test_done_documenting

@co.done_documenting = true

@store.rdoc.options.visibility = :nodoc
@store.options.visibility = :nodoc

@co.store = @store

Expand Down Expand Up @@ -236,7 +236,7 @@ def test_ignore
refute @co.document_children
assert @co.ignored?

@store.rdoc.options.visibility = :nodoc
@store.options.visibility = :nodoc

@co.store = @store

Expand Down Expand Up @@ -381,7 +381,7 @@ def test_store_equals

refute @co.document_self

@store.rdoc.options.visibility = :nodoc
@store.options.visibility = :nodoc

@co.store = @store

Expand All @@ -397,7 +397,7 @@ def test_stop_doc
refute @co.document_self
refute @co.document_children

@store.rdoc.options.visibility = :nodoc
@store.options.visibility = :nodoc

@co.store = @store

Expand All @@ -417,7 +417,7 @@ def test_suppress
refute @co.document_children
assert @co.suppressed?

@store.rdoc.options.visibility = :nodoc
@store.options.visibility = :nodoc

@co.store = @store

Expand Down
2 changes: 1 addition & 1 deletion test/rdoc/test_rdoc_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_add_method_alias
end

def test_add_method_duplicate
@store.rdoc.options.verbosity = 2
@store.options.verbosity = 2

meth1 = RDoc::AnyMethod.new nil, 'name'
meth1.record_location @store.add_file 'first.rb'
Expand Down
2 changes: 0 additions & 2 deletions test/rdoc/test_rdoc_rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def test_document # functional test
end

assert File.directory? 'ri'
assert_equal rdoc, rdoc.store.rdoc
end

store = rdoc.store
Expand All @@ -58,7 +57,6 @@ def test_document_with_dry_run # functional test
end

refute File.directory? 'doc'
assert_equal rdoc, rdoc.store.rdoc
end
assert_includes out, '100%'

Expand Down
3 changes: 0 additions & 3 deletions test/rdoc/test_rdoc_servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ def test_generator_for

assert_equal 'MAIN_PAGE.rdoc', @s.options.main_page
assert_equal 'Title', @s.options.title

assert_kind_of RDoc::RDoc, store.rdoc
assert_same generator, store.rdoc.generator
end

def test_if_modified_since
Expand Down
Loading