aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dependencies.rb
diff options
context:
space:
mode:
authorMarkus Reiter2017-07-01 05:32:19 +0200
committerGitHub2017-07-01 05:32:19 +0200
commitfd5e673d2d367eff03f1411d909ca0bbb2003a2c (patch)
treef908de0884ea7048aa79caedc726ef8a8cc12818 /Library/Homebrew/dependencies.rb
parent0a5052141d59ece4adb3c9dbd62096c7a2ed7282 (diff)
parent6a1fa87191bfef31ff1b2d47d3ebf281398a210f (diff)
downloadbrew-fd5e673d2d367eff03f1411d909ca0bbb2003a2c.tar.bz2
Merge pull request #2825 from reitermarkus/refactoring
Refactoring using `Forwardable` and `DelegateClass`.
Diffstat (limited to 'Library/Homebrew/dependencies.rb')
-rw-r--r--Library/Homebrew/dependencies.rb59
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