aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dependencies.rb
blob: b55d35c2ebd66da4fd716be0b7931bd3d9a91e8f (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 Comparable === other
      @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