Permalink
Browse files

Update Version class to support matching pre-release versions conform…

…ing to the Semantic Versioning specification. fixes #583
  • Loading branch information...
1 parent fe96a97 commit cb7e907e78181ba59243576afdc10693525725b2 @blakewatters committed Oct 7, 2012
Showing with 32 additions and 0 deletions.
  1. +14 −0 lib/cocoapods/version.rb
  2. +18 −0 spec/unit/version_spec.rb
View
14 lib/cocoapods/version.rb
@@ -1,6 +1,14 @@
module Pod
class Version < Gem::Version
+
+ # Conforms to Semantic Versioning by including a hyphen
+ VERSION_PATTERN = '[0-9]+(\.[0-9a-zA-Z\-]+)*' # :nodoc:
+ ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})*\s*\z/ # :nodoc:
+ def self.correct? version
+ version.to_s =~ ANCHORED_VERSION_PATTERN
+ end
+
# @returns A Version described by its #to_s method.
#
# @TODO The `from' part of the regexp should be remove before 1.0.0.
@@ -21,6 +29,12 @@ def self.from_string(string)
def to_s
head? ? "HEAD based on #{super}" : super
end
+
+ # Conform to Semantic Versioning instead of RubyGems
+ # pre-release gems can contain a hyphen and/or a letter
+ def prerelease?
+ @prerelease ||= @version =~ /[a-zA-Z\-]/
+ end
end
end
View
18 spec/unit/version_spec.rb
@@ -24,5 +24,23 @@ module Pod
version.should.be.head
version.to_s.should == 'HEAD based on 1.2.3'
end
+
+ it "identifies release versions" do
+ version = Version.from_string('1.0.0')
+ version.should.not.be.prerelease
+ end
+
+ it "matches Semantic Version pre-release versions" do
+ version = Version.from_string('1.0.0a1')
+ version.should.be.prerelease
+ version = Version.from_string('1.0.0-alpha')
+ version.should.be.prerelease
+ version = Version.from_string('1.0.0-alpha.1')
+ version.should.be.prerelease
+ version = Version.from_string('1.0.0-0.3.7')
+ version.should.be.prerelease
+ version = Version.from_string('1.0.0-x.7.z.92')
+ version.should.be.prerelease
+ end
end
end

0 comments on commit cb7e907

Please sign in to comment.