Version: make MacOSVersion comparison more robust

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
Jack Nagel 2012-08-22 10:10:12 -05:00
parent fd151f8999
commit f069ebd0df
2 changed files with 8 additions and 7 deletions

View File

@ -38,6 +38,13 @@ class VersionComparisonTests < Test::Unit::TestCase
assert v == 10.6 assert v == 10.6
assert v == :snow_leopard assert v == :snow_leopard
assert v < :lion assert v < :lion
# Test that we can compare against different representations
assert v <= 10.8
assert v < "10.8"
assert v < :mountain_lion
assert v < 11
assert v < Version.new(10.8)
assert Version.new(10.5) < v
end end
def test_version_interrogation def test_version_interrogation

View File

@ -37,7 +37,6 @@ class Version
include Comparable include Comparable
def initialize val, detected=false def initialize val, detected=false
return val if val.is_a? Version or val.nil?
@version = val.to_s @version = val.to_s
@detected_from_url = detected @detected_from_url = detected
end end
@ -210,17 +209,12 @@ end
# Enable things like "MacOS.version >= :lion" # Enable things like "MacOS.version >= :lion"
class MacOSVersion < Version class MacOSVersion < Version
compare do |other| compare do |other|
case other
when Symbol, Fixnum, Float, Version
super Version.new case other super Version.new case other
when :mountain_lion then 10.8 when :mountain_lion then 10.8
when :lion then 10.7 when :lion then 10.7
when :snow_leopard then 10.6 when :snow_leopard then 10.6
when :leopard then 10.5 when :leopard then 10.5
else other else other.to_s
end end
else
nil
end
end end
end end