semantic 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc5eebf14efcd2b4befcb8ba52e60629e76b445b
4
- data.tar.gz: 9ca2d53ad91425837e2c6f7741fe1226014b397f
3
+ metadata.gz: 587cd43a2f134032a864c84337c0207c3e8e495d
4
+ data.tar.gz: c7d7e9475f392a1c57b2567fa89b021edd5b4c73
5
5
  SHA512:
6
- metadata.gz: 8942617c71dcd13bff01cd7d62f21b7aab644e15938f0c946feadd2c010b8cc9f92a4f98f38af4d26dc6d5f0c4b7e1f76cf3f9e0a4598ef1dc8b2cfd45ed257f
7
- data.tar.gz: 4232989b6434c546b6ab358a78f14e9c8dd65e59ed49cf1fe15b178a131bbff3687a7290df2fbe4d252c5ba0430762b00cbac4bd4dc8ecc7c80fbf2c39425495
6
+ metadata.gz: f1f6fa899e311d1bc4de8d82271e30621cdc16cd65224dcc6c3b690564d9471a6c02ce89800f5aeed23d49efeccf9ae2ccef80abbcff0325587387a0d4dc47f9
7
+ data.tar.gz: cce04f83bb307dfc73f65968c3d73aaf1420963c1bac84e3964460ea4adb7f25857ce10ba78e4ac540542a35444b17715be7cd873e244a99aec9a3825432044c
data/README.md CHANGED
@@ -39,5 +39,5 @@ require 'semantic/core_ext'
39
39
 
40
40
  License
41
41
  -------
42
- Copyright (c) 2012 Josh Lindsey. See LICENSE for details.
42
+ Copyright (c) 2012 Josh Lindsey. See [LICENSE](LICENSE) for details.
43
43
 
@@ -1,97 +1,108 @@
1
1
  # See: http://semver.org
2
- class Semantic::Version
3
- SemVerRegexp = /^(\d+\.\d+\.\d+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$/
4
- attr_accessor :major, :minor, :patch, :pre, :build
5
-
6
- def initialize version_str
7
- raise ArgumentError.new("Not a valid SemVer Version (http://semver.org)") unless version_str =~ SemVerRegexp
8
-
9
- version, parts = version_str.split '-'
10
- if not parts.nil? and parts.include? '+'
11
- @pre, @build = parts.split '+'
12
- elsif version.include? '+'
13
- version, @build = version.split '+'
14
- else
15
- @pre = parts
16
- end
2
+ module Semantic
3
+ class Version
4
+ SemVerRegexp = /^(\d+\.\d+\.\d+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$/
5
+ attr_accessor :major, :minor, :patch, :pre, :build
17
6
 
7
+ def initialize version_str
8
+ raise ArgumentError.new("#{version_str} is not a valid SemVer Version (http://semver.org)") unless version_str =~ SemVerRegexp
18
9
 
19
- @major, @minor, @patch = version.split('.').map &:to_i
20
- end
10
+ version, parts = version_str.split '-'
11
+ if not parts.nil? and parts.include? '+'
12
+ @pre, @build = parts.split '+'
13
+ elsif version.include? '+'
14
+ version, @build = version.split '+'
15
+ else
16
+ @pre = parts
17
+ end
21
18
 
22
- def to_a
23
- [@major, @minor, @patch, @pre, @build]
24
- end
25
19
 
26
- def to_s
27
- str = [@major, @minor, @patch].join '.'
28
- str << '-' << @pre unless @pre.nil?
29
- str << '+' << @build unless @build.nil?
20
+ @major, @minor, @patch = version.split('.').map &:to_i
21
+ end
30
22
 
31
- str
32
- end
23
+ def to_a
24
+ [@major, @minor, @patch, @pre, @build]
25
+ end
33
26
 
34
- def to_h
35
- keys = [:major, :minor, :patch, :pre, :build]
36
- Hash[keys.zip(self.to_a)]
37
- end
27
+ def to_s
28
+ str = [@major, @minor, @patch].join '.'
29
+ str << '-' << @pre unless @pre.nil?
30
+ str << '+' << @build unless @build.nil?
38
31
 
39
- alias to_hash to_h
40
- alias to_array to_a
41
- alias to_string to_s
32
+ str
33
+ end
42
34
 
43
- def <=> other_version
44
- other_version = Version.new(other_version) if other_version.is_a? String
45
- compare_recursively self.to_a.dup, other_version.to_a.dup
46
- end
35
+ def to_h
36
+ keys = [:major, :minor, :patch, :pre, :build]
37
+ Hash[keys.zip(self.to_a)]
38
+ end
47
39
 
48
- def > other_version
49
- if (self <=> other_version) == 1 then true else false end
50
- end
40
+ alias to_hash to_h
41
+ alias to_array to_a
42
+ alias to_string to_s
51
43
 
52
- def < other_version
53
- if (self <=> other_version) == -1 then true else false end
54
- end
44
+ def <=> other_version
45
+ other_version = Version.new(other_version) if other_version.is_a? String
55
46
 
56
- def >= other_version
57
- if (self <=> other_version) >= 0 then true else false end
58
- end
47
+ v1 = self.dup
48
+ v2 = other_version.dup
59
49
 
60
- def <= other_version
61
- if (self <=> other_version) <= 0 then true else false end
62
- end
50
+ # The build must be excluded from the comparison, so that e.g. 1.2.3+foo and 1.2.3+bar are semantically equal.
51
+ # "Build metadata SHOULD be ignored when determining version precedence".
52
+ # (SemVer 2.0.0-rc.2, paragraph 10 - http://www.semver.org)
53
+ v1.build = nil
54
+ v2.build = nil
63
55
 
64
- def == other_version
65
- if (self <=> other_version) == 0 then true else false end
66
- end
67
-
68
- private
56
+ compare_recursively(v1.to_a, v2.to_a)
57
+ end
69
58
 
70
- def compare_recursively ary1, ary2
71
- # Short-circuit the recursion entirely if they're just equal
72
- return 0 if ary1 == ary2
59
+ def > other_version
60
+ (self <=> other_version) == 1
61
+ end
73
62
 
74
- a = ary1.shift; b = ary2.shift
63
+ def < other_version
64
+ (self <=> other_version) == -1
65
+ end
75
66
 
76
- # Reached the end of the arrays, equal all the way down
77
- return 0 if a.nil? and b.nil?
67
+ def >= other_version
68
+ (self <=> other_version) >= 0
69
+ end
78
70
 
79
- # Mismatched types (ie. one has a build and the other doesn't)
80
- if a.nil? and not b.nil?
81
- return -1
82
- elsif not a.nil? and b.nil?
83
- return 1
71
+ def <= other_version
72
+ (self <=> other_version) <= 0
84
73
  end
85
74
 
86
- # Less or greater than
87
- if a > b
88
- return 1
89
- elsif a < b
90
- return -1
75
+ def == other_version
76
+ (self <=> other_version) == 0
91
77
  end
92
78
 
93
- # Recurse down to the next part if equal
94
- compare_recursively ary1, ary2
79
+ private
80
+
81
+ def compare_recursively ary1, ary2
82
+ # Short-circuit the recursion entirely if they're just equal
83
+ return 0 if ary1 == ary2
84
+
85
+ a = ary1.shift; b = ary2.shift
86
+
87
+ # Reached the end of the arrays, equal all the way down
88
+ return 0 if a.nil? and b.nil?
89
+
90
+ # Mismatched types (ie. one has a pre and the other doesn't)
91
+ if a.nil? and not b.nil?
92
+ return 1
93
+ elsif not a.nil? and b.nil?
94
+ return -1
95
+ end
96
+
97
+ if a < b
98
+ return -1
99
+ elsif a > b
100
+ return 1
101
+ end
102
+
103
+ # Versions are equal thus far, so recurse down to the next part.
104
+ compare_recursively ary1, ary2
105
+ end
95
106
  end
96
107
  end
97
108
 
data/lib/semantic.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Semantic
2
- GEM_VERSION = '1.1.1'
2
+ GEM_VERSION = '1.2.0'
3
3
  autoload :Version, 'semantic/version'
4
4
  end
5
5
 
data/spec/version_spec.rb CHANGED
@@ -67,53 +67,83 @@ describe Semantic::Version do
67
67
 
68
68
  context "comparisons" do
69
69
  before(:each) do
70
- @v1 = Semantic::Version.new '1.5.9'
71
- @v2 = Semantic::Version.new '1.6.0'
72
- @v3 = Semantic::Version.new '1.5.9-pre.1'
73
- @v4 = Semantic::Version.new '1.5.9-pre.1+build.5127'
70
+ # These three are all semantically equivalent, according to the spec.
71
+ @v1_5_9_pre_1 = Semantic::Version.new '1.5.9-pre.1'
72
+ @v1_5_9_pre_1_build_5127 = Semantic::Version.new '1.5.9-pre.1+build.5127'
73
+ @v1_5_9_pre_1_build_4352 = Semantic::Version.new '1.5.9-pre.1+build.4352'
74
+
75
+ @v1_5_9 = Semantic::Version.new '1.5.9'
76
+ @v1_6_0 = Semantic::Version.new '1.6.0'
74
77
  end
75
78
 
76
79
  it "determines sort order" do
77
- (@v1 <=> @v2).should == -1
78
- (@v3 <=> @v1).should == 1
79
- (@v3 <=> @v4).should == -1
80
- (@v4 <=> @v4).should == 0
81
- (@v4 <=> @v1).should == 1
80
+ # The second parameter here can be a string, so we want to ensure that this kind of comparison works also.
81
+ (@v1_5_9_pre_1 <=> @v1_5_9_pre_1.to_s).should == 0
82
+
83
+ (@v1_5_9_pre_1 <=> @v1_5_9_pre_1_build_5127).should == 0
84
+ (@v1_5_9_pre_1 <=> @v1_5_9).should == -1
85
+ (@v1_5_9_pre_1_build_5127 <=> @v1_5_9).should == -1
86
+
87
+ @v1_5_9_pre_1_build_5127.build.should == 'build.5127'
82
88
 
83
- [@v3, @v1, @v2, @v4].sort.should == [@v1, @v3, @v4, @v2]
89
+ (@v1_5_9 <=> @v1_5_9).should == 0
90
+
91
+ (@v1_5_9 <=> @v1_6_0).should == -1
92
+ (@v1_6_0 <=> @v1_5_9).should == 1
93
+ (@v1_6_0 <=> @v1_5_9_pre_1).should == 1
94
+ (@v1_5_9_pre_1 <=> @v1_6_0).should == -1
95
+
96
+ [@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0]
97
+ .reverse
98
+ .sort
99
+ .should == [@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0]
84
100
  end
85
101
 
86
102
  it "determines whether it is greater than another instance" do
87
- @v1.should_not > @v2
88
- @v4.should > @v3
89
- @v2.should > @v4
90
- @v3.should_not > @v4
103
+ # These should be equal, since "Build metadata SHOULD be ignored when determining version precedence".
104
+ # (SemVer 2.0.0-rc.2, paragraph 10 - http://www.semver.org)
105
+ @v1_5_9_pre_1.should_not > @v1_5_9_pre_1_build_5127
106
+ @v1_5_9_pre_1.should_not < @v1_5_9_pre_1_build_5127
107
+
108
+ @v1_6_0.should > @v1_5_9
109
+ @v1_5_9.should_not > @v1_6_0
110
+ @v1_5_9.should > @v1_5_9_pre_1_build_5127
111
+ @v1_5_9.should > @v1_5_9_pre_1
91
112
  end
92
113
 
93
- it "determines whether it is less than another insance" do
94
- @v1.should < @v2
95
- @v2.should_not < @v4
96
- @v4.should < @v2
97
- @v3.should < @v4
114
+ it "determines whether it is less than another instance" do
115
+ @v1_5_9_pre_1.should_not < @v1_5_9_pre_1_build_5127
116
+ @v1_5_9_pre_1_build_5127.should_not < @v1_5_9_pre_1
117
+ @v1_5_9_pre_1.should < @v1_5_9
118
+ @v1_5_9_pre_1.should < @v1_6_0
119
+ @v1_5_9_pre_1_build_5127.should < @v1_6_0
120
+ @v1_5_9.should < @v1_6_0
98
121
  end
99
122
 
100
123
  it "determines whether it is greater than or equal to another instance" do
101
- @v1.should >= @v1
102
- @v1.should_not >= @v2
103
- @v4.should >= @v3
104
- @v2.should >= @v4
124
+ @v1_5_9_pre_1.should >= @v1_5_9_pre_1
125
+ @v1_5_9_pre_1.should >= @v1_5_9_pre_1_build_5127
126
+ @v1_5_9_pre_1_build_5127.should >= @v1_5_9_pre_1
127
+ @v1_5_9.should >= @v1_5_9_pre_1
128
+ @v1_6_0.should >= @v1_5_9
129
+ @v1_5_9_pre_1_build_5127.should_not >= @v1_6_0
105
130
  end
106
131
 
107
132
  it "determines whether it is less than or equal to another instance" do
108
- @v1.should <= @v2
109
- @v4.should_not <= $v3
110
- @v2.should <= @v2
111
- @v3.should_not <= @v1
133
+ @v1_5_9_pre_1.should <= @v1_5_9_pre_1_build_5127
134
+ @v1_6_0.should_not <= @v1_5_9
135
+ @v1_5_9_pre_1_build_5127.should <= @v1_5_9_pre_1_build_5127
136
+ @v1_5_9.should_not <= @v1_5_9_pre_1
112
137
  end
113
138
 
114
- it "determines whether it is exactly equal to another instance" do
115
- @v1.should == @v1.dup
116
- @v2.should == @v2.dup
139
+ it "determines whether it is semantically equal to another instance" do
140
+ @v1_5_9_pre_1.should == @v1_5_9_pre_1.dup
141
+ @v1_5_9_pre_1_build_5127.should == @v1_5_9_pre_1_build_5127.dup
142
+
143
+ # "Semantically equal" is the keyword here; these are by definition not "equal" (different build), but should be treated as
144
+ # equal according to the spec.
145
+ @v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1_build_5127
146
+ @v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1
117
147
  end
118
148
  end
119
149
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lindsey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-16 00:00:00.000000000 Z
11
+ date: 2013-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -82,3 +82,4 @@ test_files:
82
82
  - spec/core_ext_spec.rb
83
83
  - spec/spec_helper.rb
84
84
  - spec/version_spec.rb
85
+ has_rdoc: