semver2 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.semver +5 -5
- data/README.md +1 -1
- data/bin/semver +0 -0
- data/lib/semver.rb +37 -0
- metadata +3 -3
data/.semver
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
---
|
2
|
-
:major: 3
|
3
|
-
:minor:
|
4
|
-
:patch:
|
5
|
-
:special:
|
1
|
+
---
|
2
|
+
:major: 3
|
3
|
+
:minor: 1
|
4
|
+
:patch: 0
|
5
|
+
:special: ''
|
data/README.md
CHANGED
data/bin/semver
CHANGED
File without changes
|
data/lib/semver.rb
CHANGED
@@ -100,4 +100,41 @@ class SemVer
|
|
100
100
|
end
|
101
101
|
|
102
102
|
include Comparable
|
103
|
+
|
104
|
+
# Parses a semver from a string and format.
|
105
|
+
def self.parse(version_string, format = nil, allow_missing = true)
|
106
|
+
format ||= TAG_FORMAT
|
107
|
+
regex_str = Regexp.escape format
|
108
|
+
|
109
|
+
# Convert all the format characters to named capture groups
|
110
|
+
regex_str = regex_str.gsub('%M', '(?<major>\d+)').
|
111
|
+
gsub('%m', '(?<minor>\d+)').
|
112
|
+
gsub('%p', '(?<patch>\d+)').
|
113
|
+
gsub('%s', '(?:-(?<special>[A-Za-z][0-9A-Za-z\.]+))?')
|
114
|
+
|
115
|
+
regex = Regexp.new(regex_str)
|
116
|
+
match = regex.match version_string
|
117
|
+
|
118
|
+
if match
|
119
|
+
major = minor = patch = nil
|
120
|
+
special = ''
|
121
|
+
|
122
|
+
# Extract out the version parts
|
123
|
+
major = match[:major].to_i if match.names.include? 'major'
|
124
|
+
minor = match[:minor].to_i if match.names.include? 'minor'
|
125
|
+
patch = match[:patch].to_i if match.names.include? 'patch'
|
126
|
+
special = match[:special] || '' if match.names.include? 'special'
|
127
|
+
|
128
|
+
# Failed parse if major, minor, or patch wasn't found
|
129
|
+
# and allow_missing is false
|
130
|
+
return nil if !allow_missing and [major, minor, patch].any? {|x| x.nil? }
|
131
|
+
|
132
|
+
# Otherwise, allow them to default to zero
|
133
|
+
major ||= 0
|
134
|
+
minor ||= 0
|
135
|
+
patch ||= 0
|
136
|
+
|
137
|
+
SemVer.new major, minor, patch, special
|
138
|
+
end
|
139
|
+
end
|
103
140
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semver2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: maintain versions as per http://semver.org
|
16
16
|
email: henrik@haf.se
|
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
version: '0'
|
46
46
|
requirements: []
|
47
47
|
rubyforge_project:
|
48
|
-
rubygems_version: 1.8.
|
48
|
+
rubygems_version: 1.8.24
|
49
49
|
signing_key:
|
50
50
|
specification_version: 3
|
51
51
|
summary: Semantic Versioning
|