diff options
author | Cody Cutrer <[email protected]> | 2023-09-15 09:32:30 -0600 |
---|---|---|
committer | git <[email protected]> | 2023-11-01 02:29:56 +0000 |
commit | 836d9fe46b85dd28339d2dae891df2da153c8632 (patch) | |
tree | 0daa15a9efa18a953de9c434984a46c7492cc53a | |
parent | c3b7f275613507334fc4dcbfde0491ddaa786323 (diff) |
[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
-rw-r--r-- | lib/bundler/plugin.rb | 12 |
1 files 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<String>] 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 |