forked from Homebrew/brew
/
dependencies.rb
70 lines (55 loc) 路 1.08 KB
/
dependencies.rb
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
# typed: true
# frozen_string_literal: true
require "delegate"
# A collection of dependencies.
#
# @api private
class Dependencies < SimpleDelegator
extend T::Sig
def initialize(*args)
super(args)
end
alias eql? ==
def optional
__getobj__.select(&:optional?)
end
def recommended
__getobj__.select(&:recommended?)
end
def build
__getobj__.select(&:build?)
end
def required
__getobj__.select(&:required?)
end
def default
build + required + recommended
end
sig { returns(String) }
def inspect
"#<#{self.class.name}: #{__getobj__}>"
end
end
# A collection of requirements.
#
# @api private
class Requirements < SimpleDelegator
extend T::Sig
def initialize(*args)
super(Set.new(args))
end
def <<(other)
if other.is_a?(Object) && other.is_a?(Comparable)
__getobj__.grep(other.class) do |req|
return self if req > other
__getobj__.delete(req)
end
end
super
self
end
sig { returns(String) }
def inspect
"#<#{self.class.name}: {#{__getobj__.to_a.join(", ")}}>"
end
end