aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2012-08-04 00:26:59 -0500
committerJack Nagel2012-08-18 11:13:54 -0500
commit822aeac407fb92c8a6e61f48d786d3d3442ca731 (patch)
treebd3044da96d746ba48a82729da9ba2ca758dde32 /Library
parent610c65c908f8612e33fa5c6a6004d967ddad6baa (diff)
downloadhomebrew-822aeac407fb92c8a6e61f48d786d3d3442ca731.tar.bz2
Add custom comparator for MacOS.version
This will allow us to do comparisons like if MacOS.version >= :lion and hopefully deprecate the MacOS.<name>? family of methods, which are counterinitutive.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/macos.rb3
-rw-r--r--Library/Homebrew/test/test_versions.rb7
-rw-r--r--Library/Homebrew/version.rb18
3 files changed, 27 insertions, 1 deletions
diff --git a/Library/Homebrew/macos.rb b/Library/Homebrew/macos.rb
index f5304430b..1fd7d928f 100644
--- a/Library/Homebrew/macos.rb
+++ b/Library/Homebrew/macos.rb
@@ -3,7 +3,8 @@ module MacOS extend self
MDITEM_BUNDLE_ID_KEY = "kMDItemCFBundleIdentifier"
def version
- MACOS_VERSION
+ require 'version'
+ MacOSVersion.new(MACOS_VERSION.to_s)
end
def cat
diff --git a/Library/Homebrew/test/test_versions.rb b/Library/Homebrew/test/test_versions.rb
index ab6f83991..972ce130b 100644
--- a/Library/Homebrew/test/test_versions.rb
+++ b/Library/Homebrew/test/test_versions.rb
@@ -24,6 +24,13 @@ class VersionComparisonTests < Test::Unit::TestCase
assert_version_comparison 'HEAD', '>', '1.2.3'
assert_version_comparison '1.2.3', '<', 'HEAD'
end
+
+ def test_macos_version_comparison
+ v = MacOSVersion.new(10.6)
+ assert v == 10.6
+ assert v == :snow_leopard
+ assert v < :lion
+ end
end
class VersionParsingTests < Test::Unit::TestCase
diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb
index 7936efc80..30e41392a 100644
--- a/Library/Homebrew/version.rb
+++ b/Library/Homebrew/version.rb
@@ -154,3 +154,21 @@ class VersionSchemeDetector
raise "Unknown version scheme #{@scheme} was requested."
end
end
+
+# Enable things like "MacOS.version >= :lion"
+class MacOSVersion < Version
+ compare do |other|
+ case other
+ when Symbol, Fixnum, Float, Version
+ super Version.new case other
+ when :mountain_lion then 10.8
+ when :lion then 10.7
+ when :snow_leopard then 10.6
+ when :leopard then 10.5
+ else other
+ end
+ else
+ nil
+ end
+ end
+end