From 836d9fe46b85dd28339d2dae891df2da153c8632 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 15 Sep 2023 09:32:30 -0600 Subject: [PATCH] [rubygems/rubygems] Add Bundler::Plugin.loaded? helper Useful if your plugin introduces new methods to the DSL, so that Gemfiles can easily abort if the plugin hasn't loaded yet https://github.com/rubygems/rubygems/commit/b733055c6e --- lib/bundler/plugin.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index edd1900135..fbbb5950f7 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "set" + require_relative "plugin/api" module Bundler @@ -25,7 +27,7 @@ module Bundler @sources = {} @commands = {} @hooks_by_event = Hash.new {|h, k| h[k] = [] } - @loaded_plugin_names = [] + @loaded_plugin_names = Set.new end reset! @@ -228,7 +230,7 @@ module Bundler plugins = index.hook_plugins(event) return unless plugins.any? - (plugins - @loaded_plugin_names).each {|name| load_plugin(name) } + plugins.each {|name| load_plugin(name) } @hooks_by_event[event].each {|blk| blk.call(*args, &arg_blk) } end @@ -240,6 +242,11 @@ module Bundler Index.new.installed?(plugin) end + # @return [true, false] whether the plugin is loaded + def loaded?(plugin) + @loaded_plugin_names.include?(plugin) + end + # Post installation processing and registering with index # # @param [Array] plugins list to be installed @@ -330,6 +337,7 @@ module Bundler # @param [String] name of the plugin def load_plugin(name) return unless name && !name.empty? + return if loaded?(name) # Need to ensure before this that plugin root where the rest of gems # are installed to be on load path to support plugin deps. Currently not