Skip to content

Commit

Permalink
Add attribute :force to RDoc::RubygemsHook just like RDoc::RubyGemsHo…
Browse files Browse the repository at this point in the history
…ok (#1244)

Rubygems creates an instance of RDoc::RubygemsHook, sets `doc.force = overwrite`, then calls `doc.generate` the document.
RDoc::RubygemsHook needs attribute `:force` just like RDoc::RubyGemsHook.
  • Loading branch information
tompng authored Dec 16, 2024
1 parent c6193bf commit 01bdbcd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/rdoc/rubygems_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def setup
module RDoc
class RubygemsHook

attr_accessor :generate_rdoc, :generate_ri
attr_accessor :generate_rdoc, :generate_ri, :force

def self.default_gem?
!File.exist?(File.join(__dir__, "..", "rubygems_plugin.rb"))
Expand All @@ -281,14 +281,17 @@ def initialize(spec, generate_rdoc = false, generate_ri = true)
@spec = spec
@generate_rdoc = generate_rdoc
@generate_ri = generate_ri
@force = false
end

def generate
# Do nothing if this is NOT a default gem.
return unless self.class.default_gem?

# Generate document for compatibility if this is a default gem.
RubyGemsHook.new(@spec, @generate_rdoc, @generate_ri).generate
hook = RubyGemsHook.new(@spec, @generate_rdoc, @generate_ri)
hook.force = @force
hook.generate
end

def remove
Expand Down
19 changes: 19 additions & 0 deletions test/rdoc/test_rdoc_rubygems_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,25 @@ def test_generate_force
assert_path_exist File.join(@a.doc_dir('ri'), 'cache.ri')
end

def test_generate_rubygems_compatible
original_default_gem_method = RDoc::RubygemsHook.method(:default_gem?)
RDoc::RubygemsHook.singleton_class.remove_method(:default_gem?)
RDoc::RubygemsHook.define_singleton_method(:default_gem?) { true }
FileUtils.mkdir_p @a.doc_dir 'ri'
FileUtils.mkdir_p @a.doc_dir 'rdoc'
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')

# rubygems/lib/rubygems/commands/rdoc_command.rb calls this
hook = RDoc::RubygemsHook.new @a, true, true
hook.force = true
hook.generate

assert_path_exist File.join(@a.doc_dir('rdoc'), 'index.html')
ensure
RDoc::RubygemsHook.singleton_class.remove_method(:default_gem?)
RDoc::RubygemsHook.define_singleton_method(:default_gem?, &original_default_gem_method)
end

def test_generate_no_overwrite
FileUtils.mkdir_p @a.doc_dir 'ri'
FileUtils.mkdir_p @a.doc_dir 'rdoc'
Expand Down

0 comments on commit 01bdbcd

Please sign in to comment.