Skip to content

Commit

Permalink
Avoid warning when requiring bigdecimal/util when bigdecimal is in ge…
Browse files Browse the repository at this point in the history
…mfile
  • Loading branch information
segiddins authored and hsbt committed Dec 16, 2023
1 parent 6f6b36b commit 83bdf12
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/bundled_gems.rb
Expand Up @@ -59,10 +59,12 @@ module Gem::BUNDLED_GEMS
def self.replace_require(specs)
return if [::Kernel.singleton_class, ::Kernel].any? {|klass| klass.respond_to?(:no_warning_require) }

spec_names = specs.to_a.each_with_object({}) {|spec, h| h[spec.name] = true }

[::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: specs) # rubocop:disable Style/HashSyntax
if message = ::Gem::BUNDLED_GEMS.warning?(name, specs: spec_names) # rubocop:disable Style/HashSyntax
warn message, :uplevel => 1
end
kernel_class.send(:no_warning_require, name)
Expand Down Expand Up @@ -90,10 +92,12 @@ def self.find_gem(path)

def self.warning?(name, specs: nil)
feature = File.path(name) # name can be a feature name or a file path with String or Pathname
name = feature.tr("/", "-").sub(LIBEXT, "")
return if specs.to_a.map(&:name).include?(name)
name = feature.tr("/", "-")
name.sub!(LIBEXT, "")
return if specs.include?(name)
_t, path = $:.resolve_feature_path(feature)
if gem = find_gem(path)
return if specs.include?(gem)
caller = caller_locations(3, 3).find {|c| c&.absolute_path}
return if find_gem(caller&.absolute_path)
elsif SINCE[name]
Expand Down

0 comments on commit 83bdf12

Please sign in to comment.