From 6709bc25e1459cb60f78902d12afdef88645d810 Mon Sep 17 00:00:00 2001 From: Vít Ondruch Date: Wed, 8 Mar 2023 18:32:53 +0100 Subject: Fix `RuntimeError` having multiple plugins installed Having multiple RubyGems plugins installed (e.g. rubygems-server) in addition to RDoc, the original code was too conservative and causing errors such as: ~~~ $ gem server Error loading RubyGems plugin "/usr/share/gems/plugins/rdoc-generator-fedora-darkfish_plugin.rb": (RuntimeError) Server started at http://0.0.0.0:8808 Server started at http://[::]:8808 ... snip .. ~~~ or ~~~ $ gem list Error loading RubyGems plugin "/usr/share/gems/plugins/rdoc-generator-fedora-darkfish_plugin.rb": (RuntimeError) *** LOCAL GEMS *** abbrev (default: 0.1.1) ... snip ... ~~~ Newly try to load the RDoc hooks and check if we have only one hook afterwards and assume that is the right one. It would be nice to be able to compare if the hook really is the expected `Gem::RDoc.method(:generation_hook)`, but there is no way to do it easily to my knowledge. --- rubygems_plugin.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rubygems_plugin.rb b/rubygems_plugin.rb index 84eeba7..42f50ba 100644 --- a/rubygems_plugin.rb +++ b/rubygems_plugin.rb @@ -1,12 +1,12 @@ -# Make sure there are no `done_installing` hooks defined yet, so there is know -# starting position. -raise unless Gem.done_installing_hooks.empty? - # Initialize the RubyGems RDoc hook. require "rubygems/rdoc" -# Double check that there is only one `done_installing` hook loaded. -raise unless Gem.done_installing_hooks.size == 1 +# Make sure there is only one `done_installing`, so we can assume it it the +# RDod defined one. +raise <<~ERR unless Gem.done_installing_hooks.size == 1 + rdoc-generator-fedora-darkfish expects only one `Gem.done_installing_hooks` + at this stage, but #{Gem.done_installing_hooks.size} are defined +ERR # Subsequently drop the hook. Gem.done_installing_hooks.pop -- cgit