Skip to content

Commit

Permalink
Improve bundled gems warnings for subfeatures
Browse files Browse the repository at this point in the history
Before, when requiring "bigdecimal/math" in a Bundler context:

> /Users/deivid/.asdf/installs/ruby/3.3.0-dev/lib/ruby/3.3.0+0/bigdecimal/math.rb:2: warning: bigdecimal was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.4.0. Add bigdecimal to your Gemfile or gemspec.

After:

> foo.rb:1: warning: bigdecimal/math is found in bigdecimal, which will no longer be part of the default gems since Ruby 3.4.0. Add bigdecimal to your Gemfile or gemspec.
  • Loading branch information
deivid-rodriguez authored and hsbt committed Dec 8, 2023
1 parent a530dfe commit 64e9853
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/bundled_gems.rb
Expand Up @@ -89,10 +89,10 @@ def self.find_gem(path)
end

def self.warning?(name, specs: nil)
name = File.path(name) # name can be a feature name or a file path with String or Pathname
return if specs.to_a.map(&:name).include?(name.sub(LIBEXT, ""))
name = name.tr("/", "-")
_t, path = $:.resolve_feature_path(name)
feature = File.path(name) # name can be a feature name or a file path with String or Pathname
return if specs.to_a.map(&:name).include?(feature.sub(LIBEXT, ""))
_t, path = $:.resolve_feature_path(feature)
name = feature.tr("/", "-")
if gem = find_gem(path)
caller = caller_locations(3, 3).find {|c| c&.absolute_path}
return if find_gem(caller&.absolute_path)
Expand All @@ -106,11 +106,11 @@ def self.warning?(name, specs: nil)
WARNED[name] = true
if gem == true
gem = name
"#{name} was loaded from the standard library, but"
"#{feature} was loaded from the standard library, but"
elsif gem
return if WARNED[gem]
WARNED[gem] = true
"#{name} is found in #{gem}, which"
"#{feature} is found in #{gem}, which"
else
return
end + build_message(gem)
Expand Down

0 comments on commit 64e9853

Please sign in to comment.