Only `warn` about bundled gems when require succeeds

This commit is contained in:
David Rodríguez 2024-09-04 22:01:03 +02:00 коммит произвёл Hiroshi SHIBATA
Родитель a896c4cc53
Коммит a70adce1ce
1 изменённых файлов: 5 добавлений и 2 удалений

Просмотреть файл

@ -69,14 +69,17 @@ module Gem::BUNDLED_GEMS
[::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)