[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
This commit is contained in:
parent
c3b7f27561
commit
836d9fe46b
@ -1,5 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "set"
|
||||||
|
|
||||||
require_relative "plugin/api"
|
require_relative "plugin/api"
|
||||||
|
|
||||||
module Bundler
|
module Bundler
|
||||||
@ -25,7 +27,7 @@ module Bundler
|
|||||||
@sources = {}
|
@sources = {}
|
||||||
@commands = {}
|
@commands = {}
|
||||||
@hooks_by_event = Hash.new {|h, k| h[k] = [] }
|
@hooks_by_event = Hash.new {|h, k| h[k] = [] }
|
||||||
@loaded_plugin_names = []
|
@loaded_plugin_names = Set.new
|
||||||
end
|
end
|
||||||
|
|
||||||
reset!
|
reset!
|
||||||
@ -228,7 +230,7 @@ module Bundler
|
|||||||
plugins = index.hook_plugins(event)
|
plugins = index.hook_plugins(event)
|
||||||
return unless plugins.any?
|
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) }
|
@hooks_by_event[event].each {|blk| blk.call(*args, &arg_blk) }
|
||||||
end
|
end
|
||||||
@ -240,6 +242,11 @@ module Bundler
|
|||||||
Index.new.installed?(plugin)
|
Index.new.installed?(plugin)
|
||||||
end
|
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
|
# Post installation processing and registering with index
|
||||||
#
|
#
|
||||||
# @param [Array<String>] plugins list to be installed
|
# @param [Array<String>] plugins list to be installed
|
||||||
@ -330,6 +337,7 @@ module Bundler
|
|||||||
# @param [String] name of the plugin
|
# @param [String] name of the plugin
|
||||||
def load_plugin(name)
|
def load_plugin(name)
|
||||||
return unless name && !name.empty?
|
return unless name && !name.empty?
|
||||||
|
return if loaded?(name)
|
||||||
|
|
||||||
# Need to ensure before this that plugin root where the rest of gems
|
# 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
|
# are installed to be on load path to support plugin deps. Currently not
|
||||||
|
Loading…
x
Reference in New Issue
Block a user