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.



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

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

Instance Method Details

#add(req) ⇒ Object

Adds Resolver::DependencyRequest req to this requirements list.



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

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

#eachObject

Enumerates requirements in the list



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

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)


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

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

#initialize_copy(other) ⇒ Object

:nodoc:



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

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

#next5Object

Returns the oldest five entries from the list.



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

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

#removeObject

Remove the oldest DependencyRequest from the list.



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

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

#sizeObject

How many elements are in the list



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

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