summaryrefslogtreecommitdiff
path: root/lib/rubygems/dependency.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/dependency.rb')
-rw-r--r--lib/rubygems/dependency.rb38
1 files changed, 20 insertions, 18 deletions
diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb
index 85f8609677..d1bf074441 100644
--- a/lib/rubygems/dependency.rb
+++ b/lib/rubygems/dependency.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
##
# The Dependency class holds a Gem name and a Gem::Requirement.
@@ -45,10 +46,10 @@ class Gem::Dependency
end
type = Symbol === requirements.last ? requirements.pop : :runtime
- requirements = requirements.first if 1 == requirements.length # unpack
+ requirements = requirements.first if requirements.length == 1 # unpack
unless TYPES.include? type
- raise ArgumentError, "Valid types are #{TYPES.inspect}, " +
+ raise ArgumentError, "Valid types are #{TYPES.inspect}, " \
"not #{type.inspect}"
end
@@ -73,11 +74,9 @@ class Gem::Dependency
def inspect # :nodoc:
if prerelease?
- "<%s type=%p name=%p requirements=%p prerelease=ok>" %
- [self.class, self.type, self.name, requirement.to_s]
+ format("<%s type=%p name=%p requirements=%p prerelease=ok>", self.class, type, name, requirement.to_s)
else
- "<%s type=%p name=%p requirements=%p>" %
- [self.class, self.type, self.name, requirement.to_s]
+ format("<%s type=%p name=%p requirements=%p>", self.class, type, name, requirement.to_s)
end
end
@@ -168,16 +167,16 @@ class Gem::Dependency
def ==(other) # :nodoc:
Gem::Dependency === other &&
- self.name == other.name &&
- self.type == other.type &&
- self.requirement == other.requirement
+ name == other.name &&
+ type == other.type &&
+ requirement == other.requirement
end
##
# Dependencies are ordered by name.
def <=>(other)
- self.name <=> other.name
+ name <=> other.name
end
##
@@ -204,7 +203,7 @@ class Gem::Dependency
requirement.satisfied_by? version
end
- alias === =~
+ alias_method :===, :=~
##
# :call-seq:
@@ -262,7 +261,7 @@ class Gem::Dependency
end
default = Gem::Requirement.default
- self_req = self.requirement
+ self_req = requirement
other_req = other.requirement
return self.class.new name, self_req if other_req == default
@@ -277,7 +276,10 @@ class Gem::Dependency
requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version)
end.map(&:to_spec)
- Gem::BundlerVersionFinder.prioritize!(matches) if prioritizes_bundler?
+ if prioritizes_bundler?
+ require_relative "bundler_version_finder"
+ Gem::BundlerVersionFinder.prioritize!(matches)
+ end
if platform_only
matches.reject! do |spec|
@@ -296,7 +298,7 @@ class Gem::Dependency
end
def prioritizes_bundler?
- name == "bundler".freeze && !specific?
+ name == "bundler" && !specific?
end
def to_specs
@@ -320,15 +322,15 @@ class Gem::Dependency
end
def to_spec
- matches = self.to_specs.compact
+ matches = to_specs.compact
- active = matches.find {|spec| spec.activated? }
+ active = matches.find(&:activated?)
return active if active
unless prerelease?
- # Move prereleases to the end of the list for >= 0 requirements
+ # Consider prereleases only as a fallback
pre, matches = matches.partition {|spec| spec.version.prerelease? }
- matches += pre if requirement == Gem::Requirement.default
+ matches = pre if matches.empty?
end
matches.first