summaryrefslogtreecommitdiff
path: root/lib/bundler/plugin.rb
diff options
context:
space:
mode:
authorjules2689 <julian@jnadeau.ca>2018-05-22 22:22:29 -0400
committerjules2689 <julian@jnadeau.ca>2018-05-22 22:59:47 -0400
commitae2237f6db2d690ddba43b692b9700ef64adda61 (patch)
tree1831cab83c91143618c6708b039026ffbc99e5a5 /lib/bundler/plugin.rb
parentc793c38a55559677573d28d4bfadd811e8508b48 (diff)
downloadbundler-ae2237f6db2d690ddba43b692b9700ef64adda61.tar.gz
Make all plugin events registered to make documenting them easier
Every event in #hook and #add_hook will check if the event is registered in Bundler::Plugin::Events. This allows for easy tracking of what's calling events, and allow documentation to easily point to a single location. It also makes testing easier as events are predicatable and accessible via constants
Diffstat (limited to 'lib/bundler/plugin.rb')
-rw-r--r--lib/bundler/plugin.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb
index 127f1f64c0..422d4acfbc 100644
--- a/lib/bundler/plugin.rb
+++ b/lib/bundler/plugin.rb
@@ -5,6 +5,7 @@ require "bundler/plugin/api"
module Bundler
module Plugin
autoload :DSL, "bundler/plugin/dsl"
+ autoload :Events, "bundler/plugin/events"
autoload :Index, "bundler/plugin/index"
autoload :Installer, "bundler/plugin/installer"
autoload :SourceList, "bundler/plugin/source_list"
@@ -175,6 +176,9 @@ module Bundler
# To be called via the API to register a hooks and corresponding block that
# will be called to handle the hook
def add_hook(event, &block)
+ unless Events.defined_event?(event)
+ raise ArgumentError, "Event '#{event}' not defined in Bundler::Plugin::Events"
+ end
@hooks_by_event[event.to_s] << block
end
@@ -186,6 +190,9 @@ module Bundler
# @param [String] event
def hook(event, *args, &arg_blk)
return unless Bundler.feature_flag.plugins?
+ unless Events.defined_event?(event)
+ raise ArgumentError, "Event '#{event}' not defined in Bundler::Plugin::Events"
+ end
plugins = index.hook_plugins(event)
return unless plugins.any?