Skip to content

Commit c402f3b

Browse files
committed
Add new hooks around fetching gems and git sources
1 parent 4eb91f1 commit c402f3b

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

bundler/lib/bundler/plugin/events.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ def self.defined_event?(event)
4545
# GEM_AFTER_INSTALL = "after-install"
4646
define :GEM_AFTER_INSTALL, "after-install"
4747

48+
# @!parse
49+
# A hook called before each individual gem is fetched for installation.
50+
# Includes a Bundler::ParallelInstaller::SpecInstallation and a source reference.
51+
# GEM_BEFORE_FETCH = "before-fetch"
52+
define :GEM_BEFORE_FETCH, "before-fetch"
53+
54+
# @!parse
55+
# A hook called after each individual gem is fetched for installation.
56+
# Includes a Bundler::ParallelInstaller::SpecInstallation and a source reference.
57+
# GEM_AFTER_FETCH = "after-fetch"
58+
define :GEM_AFTER_FETCH, "after-fetch"
59+
60+
# @!parse
61+
# A hook called before a git source is fetched.
62+
# Includes a Bundler::Source::Git reference.
63+
# GIT_GEM_BEFORE_FETCH = "git-before-fetch"
64+
define :GIT_BEFORE_FETCH, "git-before-fetch"
65+
66+
# @!parse
67+
# A hook called after a git source is fetched.
68+
# Includes a Bundler::Source::Git reference.
69+
# GEM_AFTER_FETCH = "git-after-fetch"
70+
define :GIT_AFTER_FETCH, "git-after-fetch"
71+
4872
# @!parse
4973
# A hook called before any gems install
5074
# Includes an Array of Bundler::Dependency objects

bundler/lib/bundler/source/git.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ def specs(*)
193193
if requires_checkout? && !@copied
194194
FileUtils.rm_rf(app_cache_path) if use_app_cache? && git_proxy.not_a_repository?
195195

196+
Plugin.hook(Plugin::Events::GIT_BEFORE_FETCH, self)
196197
fetch
197198
checkout
199+
Plugin.hook(Plugin::Events::GIT_AFTER_FETCH, self)
198200
end
199201

200202
local_specs
@@ -207,7 +209,9 @@ def install(spec, options = {})
207209
print_using_message "Using #{version_message(spec, options[:previous_spec])} from #{self}"
208210

209211
if (requires_checkout? && !@copied) || force
212+
Plugin.hook(Plugin::Events::GEM_BEFORE_FETCH, spec, self)
210213
checkout
214+
Plugin.hook(Plugin::Events::GEM_AFTER_FETCH, spec, self)
211215
end
212216

213217
generate_bin_options = { disable_extensions: !spec.missing_extensions?, build_args: options[:build_args] }

bundler/lib/bundler/source/rubygems.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,14 @@ def fetch_names(fetchers, dependency_names, index)
416416
end
417417

418418
def fetch_gem_if_possible(spec, previous_spec = nil)
419-
if spec.remote
419+
Plugin.hook(Plugin::Events::GEM_BEFORE_FETCH, spec, self)
420+
gem_path = if spec.remote
420421
fetch_gem(spec, previous_spec)
421422
else
422423
cached_gem(spec)
423424
end
425+
Plugin.hook(Plugin::Events::GEM_AFTER_FETCH, spec, self)
426+
gem_path
424427
end
425428

426429
def fetch_gem(spec, previous_spec = nil)

0 commit comments

Comments
 (0)