sem_version 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +15 -0
  2. data/README.md +26 -23
  3. data/lib/sem_version.rb +20 -23
  4. metadata +5 -7
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTBhNmE0MGMxY2ExYzg2NzFiMjIxYjE4ODJjOTNjMGVmZDM4MzNiMw==
5
+ data.tar.gz: !binary |-
6
+ OTcxOTA2ZWNmZTU3NzYxYzM5MzY4ODBhNzM0ZDIzMmRhZDkwYzk1ZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MmIxMGM1ODRkNTUxM2Q2MDAxNGUwOGEwMDlhNWU0MmQ1ODM5NGQ3YjU4ZmVm
10
+ ZDJmNDVkN2JkNzc1ZDdlZGYyN2U5MjI2YzVlODU5MzU3YmYxY2YwZDgwZDcw
11
+ ZTUwNDkwODc0OTRiMDMxNDdlNWU2YjMyNjc4NGU2MDk3YTY3NmM=
12
+ data.tar.gz: !binary |-
13
+ ZjI3ZGUxZDc5Y2NiNzBmNjkxNTRiN2JlZWYyYTI5NGRmOGI1OTMxYzVkYWYz
14
+ YTA4MjZhYTY4MjIxMzIwZjc2NGZhNjhiNTNmYzJmNWEzZTNkNWM2NDU5ZGQ2
15
+ MWM4NDA3NzRmMzM1MzJkNzI0MWUwMDIwYzc0NDc3YzNhYTJkZWQ=
data/README.md CHANGED
@@ -3,13 +3,16 @@ SemVersion
3
3
 
4
4
  SemVersion is a gem to help parse, validate, modify, and compare [Semantic Versions](http://semver.org).
5
5
 
6
+ Note that this version of the gem adheres to SemVer v2.0.0.
7
+ If you want v1.0.0 behaviour, use the `semver-v1.0.0` branch.
8
+
6
9
  Parsing
7
10
  -------
8
11
 
9
12
  Parsing is easy:
10
13
 
11
14
  ```ruby
12
- v = SemVersion.new('1.2.3-pre.4+build.5')
15
+ v = SemVersion.new('1.2.3-pre.4+metadata.5')
13
16
 
14
17
  v.major # => 1
15
18
  v.minor # => 2
@@ -17,9 +20,9 @@ v.patch # => 3
17
20
 
18
21
  v.pre # => 'pre.4'
19
22
  v.prerelease # => 'pre.4'
20
- v.build # => 'build.5'
23
+ v.metadata # => 'metadata.5'
21
24
 
22
- v.to_s # => '1.2.3-pre.4+build.5'
25
+ v.to_s # => '1.2.3-pre.4+metadata.5'
23
26
  ```
24
27
 
25
28
  You can pass any valid semantic version string, as specified by [Semantic Versions](http://semver.org).
@@ -28,20 +31,20 @@ Invalid versions will raise an ArgumentError.
28
31
  You can also create a new SemVersion from an array or a hash, and serialise back to arrays and hashes.
29
32
 
30
33
  ```ruby
31
- v1 = SemVersion.new([1, 2, 3, 'pre.4', 'build.5'])
32
- v1.to_s # => '1.2.3-pre.4+build.5'
33
- v1.to_a # => [1, 2, 3, 'pre.4', 'build.5']
34
+ v1 = SemVersion.new([1, 2, 3, 'pre.4', 'metadata.5'])
35
+ v1.to_s # => '1.2.3-pre.4+metadata.5'
36
+ v1.to_a # => [1, 2, 3, 'pre.4', 'metadata.5']
34
37
 
35
- v2 = SemVersion.new(1, 2, 3, nil, 'build.5')
36
- v2.to_s # => '1.2.3+build.5'
37
- v2.to_a # => [1, 2, 3, nil, 'build.5']
38
+ v2 = SemVersion.new(1, 2, 3, nil, 'metadata.5')
39
+ v2.to_s # => '1.2.3+metadata.5'
40
+ v2.to_a # => [1, 2, 3, nil, 'metadata.5']
38
41
 
39
- v3 = SemVersion.new(:major => 1, :minor => 2, :patch => 3, :pre => 'pre.4', :build => 'build.5')
40
- v.to_s # => '1.2.3-pre.4+build.5'
41
- v.to_h # => {:major => 1, :minor => 2, :patch => 3, :pre => 'pre.4', :build => 'build.5'}
42
+ v3 = SemVersion.new(:major => 1, :minor => 2, :patch => 3, :pre => 'pre.4', :metadata => 'metadata.5')
43
+ v.to_s # => '1.2.3-pre.4+metadata.5'
44
+ v.to_h # => {:major => 1, :minor => 2, :patch => 3, :pre => 'pre.4', :metadata => 'metadata.5'}
42
45
 
43
- v4 = SemVersion.new(:major => 1, :minor => 2, :patch => 3, :build => 'build.6')
44
- v4.to_h # => {:major => 1, :minor => 2, :patch => 3, :build => 'build.6'}
46
+ v4 = SemVersion.new(:major => 1, :minor => 2, :patch => 3, :metadata => 'metadata.6')
47
+ v4.to_h # => {:major => 1, :minor => 2, :patch => 3, :metadata => 'metadata.6'}
45
48
  ```
46
49
 
47
50
  You can also use `SemVersion()` as an alias for `SemVersion.new()`.
@@ -72,9 +75,9 @@ v = SemVersion.new('1.2.3')
72
75
  v.major = 3
73
76
  v.minor = 5
74
77
  v.pre = 'pre.2'
75
- v.build = 'build.x.7'
78
+ v.metadata = 'metadata.x.7'
76
79
 
77
- v.to_s # => '3.5.1-pre.2+build.x.7'
80
+ v.to_s # => '3.5.1-pre.2+metadata.x.7'
78
81
 
79
82
  v.major = -1 # => ArgumentError
80
83
  v.major = 'a' # => ArgumentError
@@ -88,9 +91,9 @@ Comparing
88
91
  You can compare semantic versions using `<`, `>`, `<=`, `>=`, `==`, and `<=>`
89
92
 
90
93
  ```ruby
91
- SemVersion.new('1.2.3') < SemVersion.new('1.2.2') # => true
92
- SemVersion.new('1.2.3-pre.1') <= SemVersion.new('1.2.3-pre') # => false
93
- SemVersion.new('1.2.3+build.11') > SemVersion.new('1.2.3+build.2') # => true
94
+ SemVersion.new('1.2.3') < SemVersion.new('1.2.2') # => true
95
+ SemVersion.new('1.2.3-pre.1') <= SemVersion.new('1.2.3-pre') # => false
96
+ SemVersion.new('1.2.3+metadata.11') > SemVersion.new('1.2.3+metadata.2') # => false
94
97
  ```
95
98
 
96
99
  Satisfying constraints
@@ -101,8 +104,8 @@ Constraints are in the form `"<comparison> <version>"`, e.g. ">= 1.2.2", "= 1.3"
101
104
 
102
105
  When using the pessimistic operation, `~>`, versions may be specified in the form `"x.y"` or `"x.y.z"` (with `"~> x.y"` meaning `">= x.y.0" && "< x+1.0.0"`, and `"~> x.y.z"` meaning `">= x.y.z" && "< x.y+1.0"`).
103
106
 
104
- When using the other operations, versions may be in the form `"x"`, `"x.y"`, or a full semantic version (including optional pre-release and build).
105
- In the former two cases, the missing versions out of minor and patch will be filled in with 0's, and the pre-release and build ignored.
107
+ When using the other operations, versions may be in the form `"x"`, `"x.y"`, or a full semantic version (including optional pre-release and metadata).
108
+ In the former two cases, the missing versions out of minor and patch will be filled in with 0's, and the pre-release and metadata ignored.
106
109
 
107
110
  ```ruby
108
111
  SemVersion.new('1.2.3').satisfies?('>= 1.2') # => true
@@ -142,5 +145,5 @@ You can also load a set of core extensions using an optional require.
142
145
  require 'sem_version'
143
146
  require 'sem_version/core_ext'
144
147
 
145
- "1.2.3+pre.4-build.5".to_version
146
- ```
148
+ "1.2.3+pre.4-metadata.5".to_version
149
+ ```
data/lib/sem_version.rb CHANGED
@@ -1,31 +1,31 @@
1
1
  class SemVersion
2
2
  include Comparable
3
3
 
4
- VERSION = '1.3.0'
4
+ VERSION = '2.0.0'
5
5
 
6
6
  # Pattern allows min and patch to be skipped. We have to do extra checking if we want them
7
7
  SEMVER_REGEX = /^(\d+)(?:\.(\d+)(?:\.(\d+)(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?(?:\+([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?)?)?$/
8
- PRE_BUILD_REGEX = /^[\dA-Za-z\-]+(\.[\dA-Za-z\-]+)*$/
8
+ PRE_METADATA_REGEX = /^[\dA-Za-z\-]+(\.[\dA-Za-z\-]+)*$/
9
9
 
10
- attr_reader :major, :minor, :patch, :pre, :build
10
+ attr_reader :major, :minor, :patch, :pre, :metadata
11
11
  alias_method :prerelease, :pre
12
12
 
13
13
  # Format were raw bits are passed in is undocumented, and not validity checked
14
14
  def initialize(*args)
15
15
  if args.first.is_a?(String)
16
- @major, @minor, @patch, @pre, @build = self.class.parse(args.first)
16
+ @major, @minor, @patch, @pre, @metadata = self.class.parse(args.first)
17
17
  # Validation should be handled at a string level by self.parse, but validate anyway
18
18
  validate
19
19
  elsif args.first.is_a?(Hash)
20
- @major, @minor, @patch, @pre, @build = args.first.values_at(:major, :minor, :patch, :pre, :build)
20
+ @major, @minor, @patch, @pre, @metadata = args.first.values_at(:major, :minor, :patch, :pre, :metadata)
21
21
  # Allow :prerelease as well
22
22
  @pre ||= args.first[:prerelease]
23
23
  validate
24
24
  elsif args.first.is_a?(Array)
25
- @major, @minor, @patch, @pre, @build = *args.first
25
+ @major, @minor, @patch, @pre, @metadata = *args.first
26
26
  validate
27
27
  else
28
- @major, @minor, @patch, @pre, @build = *args
28
+ @major, @minor, @patch, @pre, @metadata = *args
29
29
  validate
30
30
  end
31
31
  end
@@ -65,10 +65,7 @@ class SemVersion
65
65
  pre = compare_sep(@pre, other.pre, true)
66
66
  return pre unless pre == 0
67
67
 
68
- bui = compare_sep(@build, other.build, false)
69
- return bui unless bui == 0
70
-
71
- 0
68
+ return 0
72
69
  end
73
70
 
74
71
  def satisfies?(constraint)
@@ -122,33 +119,33 @@ class SemVersion
122
119
  end
123
120
 
124
121
  def pre=(val)
125
- unless val.nil? || (val.is_a?(String) && val =~ PRE_BUILD_REGEX)
122
+ unless val.nil? || (val.is_a?(String) && val =~ PRE_METADATA_REGEX)
126
123
  raise ArgumentError, "#{val} is not a valid pre-release version (must be nil, or a string following http://semver.org constraints)"
127
124
  end
128
125
  @pre = val
129
126
  end
130
127
  alias_method :prerelease=, :pre=
131
128
 
132
- def build=(val)
133
- unless val.nil? || (val.is_a?(String) && val =~ PRE_BUILD_REGEX)
134
- raise ArgumentError, "#{val} is not a valid build version (must be nil, or a string following http://semver.org constraints)"
129
+ def metadata=(val)
130
+ unless val.nil? || (val.is_a?(String) && val =~ PRE_METADATA_REGEX)
131
+ raise ArgumentError, "#{val} is not a valid metadata string (must be nil, or a string following http://semver.org constraints)"
135
132
  end
136
- @build = val
133
+ @metadata = val
137
134
  end
138
135
 
139
136
  def to_s
140
137
  r = "#{@major}.#{@minor}.#{@patch}"
141
138
  r << "-#{@pre}" if @pre
142
- r << "+#{@build}" if @build
139
+ r << "+#{@metadata}" if @metadata
143
140
  r
144
141
  end
145
142
 
146
143
  def to_a
147
- [@major, @minor, @patch, @pre, @build]
144
+ [@major, @minor, @patch, @pre, @metadata]
148
145
  end
149
146
 
150
147
  def to_h
151
- h = [:major, :minor, :patch, :pre, :build].zip(to_a)
148
+ h = [:major, :minor, :patch, :pre, :metadata].zip(to_a)
152
149
  Hash[h.reject{ |k,v| v.nil? }]
153
150
  end
154
151
 
@@ -188,15 +185,15 @@ class SemVersion
188
185
  raise ArgumentError, "Invalid version (major is not an int >= 0)" unless @major.is_a?(Fixnum) && @major >= 0
189
186
  raise ArgumentError, "Invalid version (minor is not an int >= 0)" unless @minor.is_a?(Fixnum) && @minor >= 0
190
187
  raise ArgumentError, "Invalid version (patch is not an int >= 0)" unless @patch.is_a?(Fixnum) && @patch >= 0
191
- unless @pre.nil? || (@pre.is_a?(String) && @pre =~ PRE_BUILD_REGEX)
188
+ unless @pre.nil? || (@pre.is_a?(String) && @pre =~ PRE_METADATA_REGEX)
192
189
  raise ArgumentError, "Invalid version (pre must be nil, or a string following http://semver.org contraints)"
193
190
  end
194
- unless @build.nil? || (@build.is_a?(String) && @build =~ PRE_BUILD_REGEX)
195
- raise ArgumentError, "Invalid version (build must be nil, or a string following http://semver.org contraints)"
191
+ unless @metadata.nil? || (@metadata.is_a?(String) && @metadata =~ PRE_METADATA_REGEX)
192
+ raise ArgumentError, "Invalid version (metadata must be nil, or a string following http://semver.org contraints)"
196
193
  end
197
194
  end
198
195
  end
199
196
 
200
197
  def SemVersion(*args)
201
198
  SemVersion.new(*args)
202
- end
199
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sem_version
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Antony Male
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-16 00:00:00.000000000 Z
11
+ date: 2013-07-24 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Semantic Version parsing, comparison, and constraint checking utility
15
14
  (e.g. ~> 1.2), as specified by http://semver.org/
@@ -25,27 +24,26 @@ files:
25
24
  homepage: https://github.com/canton7/sem_version
26
25
  licenses:
27
26
  - MIT
27
+ metadata: {}
28
28
  post_install_message:
29
29
  rdoc_options: []
30
30
  require_paths:
31
31
  - lib
32
32
  required_ruby_version: !ruby/object:Gem::Requirement
33
- none: false
34
33
  requirements:
35
34
  - - ! '>='
36
35
  - !ruby/object:Gem::Version
37
36
  version: 1.9.2
38
37
  required_rubygems_version: !ruby/object:Gem::Requirement
39
- none: false
40
38
  requirements:
41
39
  - - ! '>='
42
40
  - !ruby/object:Gem::Version
43
41
  version: '0'
44
42
  requirements: []
45
43
  rubyforge_project:
46
- rubygems_version: 1.8.24
44
+ rubygems_version: 2.0.5
47
45
  signing_key:
48
- specification_version: 3
46
+ specification_version: 4
49
47
  summary: ! 'SemVersion: Semantic version parsing and comparison, and constraint checking.
50
48
  See http://semver.org/'
51
49
  test_files: []