Skip to content

Commit

Permalink
Only warn about bundled gems when require succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and hsbt committed Sep 27, 2024
1 parent a896c4c commit a70adce
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/bundled_gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ def self.replace_require(specs)
[::Kernel.singleton_class, ::Kernel].each do |kernel_class|
kernel_class.send(:alias_method, :no_warning_require, :require)
kernel_class.send(:define_method, :require) do |name|
if message = ::Gem::BUNDLED_GEMS.warning?(name, specs: spec_names)
result = kernel_class.send(:no_warning_require, name)

if result && message = ::Gem::BUNDLED_GEMS.warning?(name, specs: spec_names)
if ::Gem::BUNDLED_GEMS.uplevel > 0
Kernel.warn message, uplevel: ::Gem::BUNDLED_GEMS.uplevel
else
Kernel.warn message
end
end
kernel_class.send(:no_warning_require, name)

result
end
if kernel_class == ::Kernel
kernel_class.send(:private, :require)
Expand Down

0 comments on commit a70adce

Please sign in to comment.