Skip to content
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
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
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking that we can initialize a RubyGemsHook here already, like

    def initialize(spec, generate_rdoc = false, generate_ri = true)
      @rubygems_hook = RubyGemsHook.new(spec, generate_rdoc, generate_ri)
    end

And then delegate methods to @rubygems_hook, which will handle more cases 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, implementing minimal things to clarify what method/attribute are needed in the compatibility layer is not a bad idea. I think it is the intention of the current implementation of RubygemsHook. (I', not sure)
This way, the new RubyGemsHook can easily change its method as long as RubygemsHook's methods works.

@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
Loading