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.
This commit is contained in:
parent
158b7047e5
commit
b8231fc5f3
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user