Class Gem::DependencyList
In: lib/rubygems/dependency_list.rb
Parent: Object

Methods

Included Modules

Enumerable TSort

Public Class methods

[Source]

    # File lib/rubygems/dependency_list.rb, line 14
14:   def self.from_source_index(src_index)
15:     deps = new
16: 
17:     src_index.each do |full_name, spec|
18:       deps.add spec
19:     end
20: 
21:     deps
22:   end

[Source]

    # File lib/rubygems/dependency_list.rb, line 24
24:   def initialize
25:     @specs = []
26:   end

Public Instance methods

Adds gemspecs to the dependency list.

[Source]

    # File lib/rubygems/dependency_list.rb, line 31
31:   def add(*gemspecs)
32:     @specs.push(*gemspecs)
33:   end

Return a list of the specifications in the dependency list, sorted in order so that no spec in the list depends on a gem earlier in the list.

This is useful when removing gems from a set of installed gems. By removing them in the returned order, you don‘t get into as many dependency issues.

If there are circular dependencies (yuck!), then gems will be returned in order until only the circular dependents and anything they reference are left. Then arbitrary gemspecs will be returned until the circular dependency is broken, after which gems will be returned in dependency order again.

[Source]

    # File lib/rubygems/dependency_list.rb, line 49
49:   def dependency_order
50:     sorted = strongly_connected_components.flatten
51: 
52:     result = []
53:     seen = {}
54: 
55:     sorted.each do |spec|
56:       if index = seen[spec.name] then
57:         if result[index].version < spec.version then
58:           result[index] = spec
59:         end
60:       else
61:         seen[spec.name] = result.length
62:         result << spec
63:       end
64:     end
65: 
66:     result.reverse
67:   end

Iterator over dependency_order

[Source]

    # File lib/rubygems/dependency_list.rb, line 72
72:   def each(&block)
73:     dependency_order.each(&block)
74:   end

[Source]

    # File lib/rubygems/dependency_list.rb, line 76
76:   def find_name(full_name)
77:     @specs.find { |spec| spec.full_name == full_name }
78:   end

Are all the dependencies in the list satisfied?

[Source]

    # File lib/rubygems/dependency_list.rb, line 83
83:   def ok?
84:     @specs.all? do |spec|
85:       spec.runtime_dependencies.all? do |dep|
86:         @specs.find { |s| s.satisfies_requirement? dep }
87:       end
88:     end
89:   end

Is is ok to remove a gem from the dependency list?

If removing the gemspec creates breaks a currently ok dependency, then it is NOT ok to remove the gem.

[Source]

     # File lib/rubygems/dependency_list.rb, line 97
 97:   def ok_to_remove?(full_name)
 98:     gem_to_remove = find_name full_name
 99: 
100:     siblings = @specs.find_all { |s|
101:       s.name == gem_to_remove.name &&
102:         s.full_name != gem_to_remove.full_name
103:     }
104: 
105:     deps = []
106: 
107:     @specs.each do |spec|
108:       spec.dependencies.each do |dep|
109:         deps << dep if gem_to_remove.satisfies_requirement?(dep)
110:       end
111:     end
112: 
113:     deps.all? { |dep|
114:       siblings.any? { |s|
115:         s.satisfies_requirement? dep
116:       }
117:     }
118:   end

[Source]

     # File lib/rubygems/dependency_list.rb, line 120
120:   def remove_by_name(full_name)
121:     @specs.delete_if { |spec| spec.full_name == full_name }
122:   end

Return a hash of predecessors. result[spec] is an Array of gemspecs that have a dependency satisfied by the named spec.

[Source]

     # File lib/rubygems/dependency_list.rb, line 128
128:   def spec_predecessors
129:     result = Hash.new { |h,k| h[k] = [] }
130: 
131:     specs = @specs.sort.reverse
132: 
133:     specs.each do |spec|
134:       specs.each do |other|
135:         next if spec == other
136: 
137:         other.dependencies.each do |dep|
138:           if spec.satisfies_requirement? dep then
139:             result[spec] << other
140:           end
141:         end
142:       end
143:     end
144: 
145:     result
146:   end

[Source]

     # File lib/rubygems/dependency_list.rb, line 152
152:   def tsort_each_child(node, &block)
153:     specs = @specs.sort.reverse
154: 
155:     node.dependencies.each do |dep|
156:       specs.each do |spec|
157:         if spec.satisfies_requirement? dep then
158:           begin
159:             yield spec
160:           rescue TSort::Cyclic
161:           end
162:           break
163:         end
164:       end
165:     end
166:   end

[Source]

     # File lib/rubygems/dependency_list.rb, line 148
148:   def tsort_each_node(&block)
149:     @specs.each(&block)
150:   end

[Validate]