Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Update Version.rb to support Semantic Versioning pre-release versions #584

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+32 −0
Split
View
@@ -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
@@ -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