diff options
Diffstat (limited to 'Library/Homebrew/dependencies.rb')
| -rw-r--r-- | Library/Homebrew/dependencies.rb | 59 |
1 files changed, 15 insertions, 44 deletions
diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index 951db078d..0ed0502d8 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -1,28 +1,11 @@ -class Dependencies - include Enumerable +require "delegate" - def initialize - @deps = [] +class Dependencies < DelegateClass(Array) + def initialize(*args) + super(args) 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 to_ary to_a + alias eql? == def optional select(&:optional?) @@ -44,40 +27,28 @@ class Dependencies build + required + recommended end - attr_reader :deps - protected :deps - - def ==(other) - deps == other.deps - end - alias eql? == - def inspect - "#<#{self.class.name}: #{to_a.inspect}>" + "#<#{self.class.name}: #{to_a}>" end end -class Requirements - include Enumerable - - def initialize - @reqs = Set.new - end - - def each(*args, &block) - @reqs.each(*args, &block) +class Requirements < DelegateClass(Set) + def initialize(*args) + super(Set.new(args)) end def <<(other) if other.is_a?(Comparable) - @reqs.grep(other.class) do |req| + grep(other.class) do |req| return self if req > other - @reqs.delete(req) + delete(req) end end - @reqs << other + super self end - alias to_ary to_a + def inspect + "#<#{self.class.name}: {#{to_a.join(", ")}}>" + end end |
