From e10f7c9d5b7c3097cd0d7bc3b7b7bbd2078c02cc Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 2 Nov 2023 15:46:42 +0900 Subject: [PATCH] Fix to detect gem name logic. It's mistake to migrate bundled_gems.rb from rubygems_integration.rb https://github.com/ioquatix/bake/pull/15#issuecomment-1777985097 --- lib/bundled_gems.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/bundled_gems.rb b/lib/bundled_gems.rb index 6fff10fdcf..a00de692ea 100644 --- a/lib/bundled_gems.rb +++ b/lib/bundled_gems.rb @@ -96,7 +96,10 @@ module Gem::BUNDLED_GEMS if defined?(Bundler) msg += " Add #{gem} to your Gemfile or gemspec." - location = caller_locations(2,2)[0]&.path + # We detect the gem name from caller_locations. We need to skip 2 frames like: + # lib/ruby/3.3.0+0/bundled_gems.rb:90:in `warning?'", + # lib/ruby/3.3.0+0/bundler/rubygems_integration.rb:247:in `block (2 levels) in replace_require'", + location = caller_locations(3,3)[0]&.path if File.file?(location) && !location.start_with?(Gem::BUNDLED_GEMS::LIBDIR) caller_gem = nil Gem.path.each do |path|