2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-11-18 19:34:13 -05:00
|
|
|
##
|
2013-11-25 14:14:49 -05:00
|
|
|
# The RequirementList is used to hold the requirements being considered
|
|
|
|
# while resolving a set of gems.
|
|
|
|
#
|
|
|
|
# The RequirementList acts like a queue where the oldest items are removed
|
|
|
|
# first.
|
2013-11-18 19:34:13 -05:00
|
|
|
|
|
|
|
class Gem::Resolver::RequirementList
|
|
|
|
|
|
|
|
include Enumerable
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# Creates a new RequirementList.
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def initialize
|
2013-12-07 20:22:39 -05:00
|
|
|
@exact = []
|
2013-11-18 19:34:13 -05:00
|
|
|
@list = []
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def initialize_copy(other) # :nodoc:
|
2013-12-07 20:22:39 -05:00
|
|
|
@exact = @exact.dup
|
2013-11-18 19:34:13 -05:00
|
|
|
@list = @list.dup
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# Adds Resolver::DependencyRequest +req+ to this requirements list.
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def add(req)
|
2013-12-07 20:22:39 -05:00
|
|
|
if req.requirement.exact?
|
|
|
|
@exact.push req
|
|
|
|
else
|
|
|
|
@list.push req
|
|
|
|
end
|
2013-11-18 19:34:13 -05:00
|
|
|
req
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Enumerates requirements in the list
|
|
|
|
|
|
|
|
def each # :nodoc:
|
|
|
|
return enum_for __method__ unless block_given?
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
@exact.each do |requirement|
|
|
|
|
yield requirement
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
@list.each do |requirement|
|
|
|
|
yield requirement
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
##
|
|
|
|
# How many elements are in the list
|
|
|
|
|
|
|
|
def size
|
|
|
|
@exact.size + @list.size
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# Is the list empty?
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def empty?
|
2013-12-07 20:22:39 -05:00
|
|
|
@exact.empty? && @list.empty?
|
2013-11-18 19:34:13 -05:00
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# Remove the oldest DependencyRequest from the list.
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def remove
|
2013-12-07 20:22:39 -05:00
|
|
|
return @exact.shift unless @exact.empty?
|
2013-11-18 19:34:13 -05:00
|
|
|
@list.shift
|
|
|
|
end
|
2013-11-21 18:27:30 -05:00
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# Returns the oldest five entries from the list.
|
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
def next5
|
2013-12-07 20:22:39 -05:00
|
|
|
x = @exact[0,5]
|
|
|
|
x + @list[0,5 - x.size]
|
2013-11-21 18:27:30 -05:00
|
|
|
end
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
end
|