Class: Gem::Resolver::RequirementList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubygems/resolver/requirement_list.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initializeRequirementList

Creates a new RequirementList.



16
17
18
19
# File 'lib/rubygems/resolver/requirement_list.rb', line 16

def initialize
  @exact = []
  @list = []
end

Instance Method Details

#add(req) ⇒ Object

Adds Resolver::DependencyRequest req to this requirements list.



29
30
31
32
33
34
35
36
# File 'lib/rubygems/resolver/requirement_list.rb', line 29

def add(req)
  if req.requirement.exact?
    @exact.push req
  else
    @list.push req
  end
  req
end

#eachObject

Enumerates requirements in the list



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rubygems/resolver/requirement_list.rb', line 41

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

  @exact.each do |requirement|
    yield requirement
  end

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

#empty?Boolean

Is the list empty?

Returns:

  • (Boolean)


63
64
65
# File 'lib/rubygems/resolver/requirement_list.rb', line 63

def empty?
  @exact.empty? && @list.empty?
end

#initialize_copy(other) ⇒ Object

:nodoc:



21
22
23
24
# File 'lib/rubygems/resolver/requirement_list.rb', line 21

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

#next5Object

Returns the oldest five entries from the list.



78
79
80
81
# File 'lib/rubygems/resolver/requirement_list.rb', line 78

def next5
  x = @exact[0,5]
  x + @list[0,5 - x.size]
end

#removeObject

Remove the oldest DependencyRequest from the list.



70
71
72
73
# File 'lib/rubygems/resolver/requirement_list.rb', line 70

def remove
  return @exact.shift unless @exact.empty?
  @list.shift
end

#sizeObject

How many elements are in the list



56
57
58
# File 'lib/rubygems/resolver/requirement_list.rb', line 56

def size
  @exact.size + @list.size
end