blob: c02572421caa8dd27985ebdd26867d9fa868d256 (
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
63
64
65
|
require 'tsort'
module Bundler
class SpecSet
include TSort, Enumerable
def initialize(specs)
@specs = specs.sort_by { |s| s.name }
end
def each
sorted.each { |s| yield s }
end
def length
@specs.length
end
def for(*deps)
specs = {}
deps.flatten.each do |dep|
current = lookup[dep.respond_to?(:name) ? dep.name : dep]
append_subgraph(specs, current)
end
sorted.select { |s| specs[s.name] }
end
def to_a
sorted.dup
end
private
def append_subgraph(specs, current)
return if specs[current.name]
specs[current.name] = true
current.dependencies.each do |dep|
next if dep.type == :development
append_subgraph(specs, lookup[dep.name])
end
end
def sorted
@sorted ||= ([lookup['rake']] + tsort).compact.uniq
end
def lookup
@lookup ||= Hash.new do |h,k|
h[k] = @specs.find { |s| s.name == k }
end
end
def tsort_each_node
@specs.each { |s| yield s }
end
def tsort_each_child(s)
s.dependencies.sort_by { |d| d.name }.each do |d|
next if d.type == :development
yield lookup[d.name]
end
end
end
end
|