blob: 51e5521029e18a79ce40824aee198a0c75c69017 (
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
class Dependencies
include Enumerable
def initialize
@deps = []
end
def each(*args, &block)
@deps.each(*args, &block)
end
def <<(o)
@deps << o
self
end
def empty?
@deps.empty?
end
def *(arg)
@deps * arg
end
alias_method :to_ary, :to_a
def optional
select(&:optional?)
end
def recommended
select(&:recommended?)
end
def build
select(&:build?)
end
def required
select(&:required?)
end
def default
build + required + recommended
end
attr_reader :deps
protected :deps
def ==(other)
deps == other.deps
end
alias_method :eql?, :==
def inspect
"#<#{self.class.name}: #{to_a.inspect}>"
end
end
class Requirements
include Enumerable
def initialize
@reqs = Set.new
end
def each(*args, &block)
@reqs.each(*args, &block)
end
def <<(other)
if other.is_a?(Comparable)
@reqs.grep(other.class) do |req|
return self if req > other
@reqs.delete(req)
end
end
@reqs << other
self
end
alias_method :to_ary, :to_a
end
|