aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dependencies.rb
diff options
context:
space:
mode:
authorMisty De Meo2012-10-02 13:21:00 -0500
committerMisty De Meo2012-10-15 09:46:29 -0500
commitbbfb6400c77aeaaf88216263d86491d85a40f8a9 (patch)
tree2d07e2d07653ed7d3010b2a0ca6b8019adf7a3e1 /Library/Homebrew/dependencies.rb
parent3fb5dfbd7b77e03ccd9b8aee54c198673a9cb054 (diff)
downloadbrew-bbfb6400c77aeaaf88216263d86491d85a40f8a9.tar.bz2
Manage Requirements using ComparableSet
ComparableSet only allows a single object of a given class, choosing the object with the greatest value. This was mainly created for Requirements, so that, e.g., two X11Dependencies of differing strictness don't both end up in the same requirement set. Fixes Homebrew/homebrew#15240.
Diffstat (limited to 'Library/Homebrew/dependencies.rb')
-rw-r--r--Library/Homebrew/dependencies.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb
index 5d5b5ab0d..7c2ff7d1b 100644
--- a/Library/Homebrew/dependencies.rb
+++ b/Library/Homebrew/dependencies.rb
@@ -21,7 +21,7 @@ class DependencyCollector
def initialize
@deps = Dependencies.new
- @requirements = Set.new
+ @requirements = ComparableSet.new
end
def add spec
@@ -196,6 +196,9 @@ end
# This requirement is used to require an X11 implementation,
# optionally with a minimum version number.
class X11Dependency < Requirement
+ include Comparable
+ attr_reader :min_version
+
def initialize min_version=nil
@min_version = min_version
end
@@ -217,9 +220,20 @@ class X11Dependency < Requirement
ENV.x11
end
- def hash
- "X11".hash
+ def <=> other
+ unless other.is_a? X11Dependency
+ raise TypeError, "expected X11Dependency"
+ end
+
+ if other.min_version.nil?
+ 1
+ elsif @min_version.nil?
+ -1
+ else
+ @min_version <=> other.min_version
+ end
end
+
end