Class | Gem::DependencyList |
In: |
lib/rubygems/dependency_list.rb
|
Parent: | Object |
# File lib/rubygems/dependency_list.rb, line 13 13: def self.from_source_index(src_index) 14: deps = new 15: 16: src_index.each do |full_name, spec| 17: deps.add spec 18: end 19: 20: deps 21: end
Adds gemspecs to the dependency list.
# File lib/rubygems/dependency_list.rb, line 28 28: def add(*gemspecs) 29: @specs.push(*gemspecs) 30: 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.
# File lib/rubygems/dependency_list.rb, line 45 45: def dependency_order 46: sorted = strongly_connected_components.flatten 47: 48: result = [] 49: seen = {} 50: 51: sorted.each do |spec| 52: if index = seen[spec.name] then 53: if result[index].version < spec.version then 54: result[index] = spec 55: end 56: else 57: seen[spec.name] = result.length 58: result << spec 59: end 60: end 61: 62: result.reverse 63: end
# File lib/rubygems/dependency_list.rb, line 65 65: def find_name(full_name) 66: @specs.find { |spec| spec.full_name == full_name } 67: end
Are all the dependencies in the list satisfied?
# File lib/rubygems/dependency_list.rb, line 70 70: def ok? 71: @specs.all? do |spec| 72: spec.runtime_dependencies.all? do |dep| 73: @specs.find { |s| s.satisfies_requirement? dep } 74: end 75: end 76: 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.
# File lib/rubygems/dependency_list.rb, line 82 82: def ok_to_remove?(full_name) 83: gem_to_remove = find_name full_name 84: 85: siblings = @specs.find_all { |s| 86: s.name == gem_to_remove.name && 87: s.full_name != gem_to_remove.full_name 88: } 89: 90: deps = [] 91: 92: @specs.each do |spec| 93: spec.dependencies.each do |dep| 94: deps << dep if gem_to_remove.satisfies_requirement?(dep) 95: end 96: end 97: 98: deps.all? { |dep| 99: siblings.any? { |s| 100: s.satisfies_requirement? dep 101: } 102: } 103: end
# File lib/rubygems/dependency_list.rb, line 105 105: def remove_by_name(full_name) 106: @specs.delete_if { |spec| spec.full_name == full_name } 107: end
Return a hash of predecessors. result[spec] is an Array of gemspecs that have a dependency satisfied by the named spec.
# File lib/rubygems/dependency_list.rb, line 112 112: def spec_predecessors 113: result = Hash.new { |h,k| h[k] = [] } 114: 115: specs = @specs.sort.reverse 116: 117: specs.each do |spec| 118: specs.each do |other| 119: next if spec == other 120: 121: other.dependencies.each do |dep| 122: if spec.satisfies_requirement? dep then 123: result[spec] << other 124: end 125: end 126: end 127: end 128: 129: result 130: end
# File lib/rubygems/dependency_list.rb, line 136 136: def tsort_each_child(node, &block) 137: specs = @specs.sort.reverse 138: 139: node.dependencies.each do |dep| 140: specs.each do |spec| 141: if spec.satisfies_requirement? dep then 142: begin 143: yield spec 144: rescue TSort::Cyclic 145: end 146: break 147: end 148: end 149: end 150: end