aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/resolver/requirement_list.rb
blob: fe1d77afc3b5038ef63acf3cfbf955c172546df6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
##
# 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.

class Gem::Resolver::RequirementList

  include Enumerable

  ##
  # Creates a new RequirementList.

  def initialize
    @list = []
  end

  def initialize_copy other # :nodoc:
    @list = @list.dup
  end

  ##
  # Adds Resolver::DependencyRequest +req+ to this requirements list.

  def add(req)
    @list.push req
    req
  end

  ##
  # Enumerates requirements in the list

  def each # :nodoc:
    return enum_for __method__ unless block_given?

    @list.each do |requirement|
      yield requirement
    end
  end

  ##
  # Is the list empty?

  def empty?
    @list.empty?
  end

  ##
  # Remove the oldest DependencyRequest from the list.

  def remove
    @list.shift
  end

  ##
  # Returns the oldest five entries from the list.

  def next5
    @list[0,5]
  end
end