Skip to content

Commit

Permalink
[rubygems/rubygems] Refactor Gem::Specification#find_all_by_name
Browse files Browse the repository at this point in the history
So that it can also be delegated to `Gem::SpecificationRecord`.

rubygems/rubygems@1407807a99
  • Loading branch information
deivid-rodriguez authored and matzbot committed May 16, 2024
1 parent d076101 commit 35c5c7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
14 changes: 1 addition & 13 deletions lib/rubygems/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,7 @@ def merge(other)
end

def matching_specs(platform_only = false)
env_req = Gem.env_requirement(name)
matches = Gem::Specification.stubs_for(name).find_all do |spec|
requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version)
end.map(&:to_spec)

if prioritizes_bundler?
require_relative "bundler_version_finder"
Gem::BundlerVersionFinder.prioritize!(matches)
end
matches = Gem::Specification.find_all_by_name(name, requirement)

if platform_only
matches.reject! do |spec|
Expand All @@ -297,10 +289,6 @@ def specific?
@requirement.specific?
end

def prioritizes_bundler?
name == "bundler" && !specific?
end

def to_specs
matches = matching_specs true

Expand Down
14 changes: 12 additions & 2 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,19 @@ def self.each
# Returns every spec that matches +name+ and optional +requirements+.

def self.find_all_by_name(name, *requirements)
requirements = Gem::Requirement.default if requirements.empty?
req = Gem::Requirement.create(*requirements)
env_req = Gem.env_requirement(name)

matches = stubs_for(name).find_all do |spec|
req.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version)
end.map(&:to_spec)

if name == "bundler" && !req.specific?
require_relative "bundler_version_finder"
Gem::BundlerVersionFinder.prioritize!(matches)
end

Gem::Dependency.new(name, *requirements).matching_specs
matches
end

##
Expand Down

0 comments on commit 35c5c7e

Please sign in to comment.