versus 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.index +45 -0
- data/.yardopts +7 -0
- data/HISTORY.md +11 -0
- data/Index.yml +37 -0
- data/LICENSE.txt +23 -0
- data/README.md +46 -0
- data/demo/applique/ae.rb +5 -0
- data/demo/applique/main.rb +1 -0
- data/demo/constraint/02_initialize.md +44 -0
- data/demo/constraint/04_to_proc.md +11 -0
- data/demo/constraint/09_to_gem_version.md +10 -0
- data/demo/number/02_initialize.md +14 -0
- data/demo/number/03_parse.md +23 -0
- data/demo/number/04_crush.md +17 -0
- data/demo/number/05_build.md +23 -0
- data/demo/number/06_cmp.md +100 -0
- data/demo/number/07_segments.md +51 -0
- data/demo/number/08_bump.md +46 -0
- data/demo/number/09_stable_release.md +23 -0
- data/demo/number/10_prerelease.md +19 -0
- data/demo/number/11_release_candidate.md +15 -0
- data/demo/number/19_match.md +10 -0
- data/demo/number/20_to_str.md +13 -0
- data/demo/resolver/01_initialize.md +23 -0
- data/demo/resolver/02_add.md +11 -0
- data/demo/resolver/03_libraries.md +24 -0
- data/demo/resolver/04_requirements.md +13 -0
- data/demo/resolver/05_possibilities.md +13 -0
- data/demo/resolver/06_resolve.md +42 -0
- data/lib/versus.rb +5 -0
- data/lib/versus/constraint.rb +130 -0
- data/lib/versus/core_ext.rb +4 -0
- data/lib/versus/core_ext/array.rb +11 -0
- data/lib/versus/core_ext/kernel.rb +19 -0
- data/lib/versus/core_ext/string.rb +10 -0
- data/lib/versus/exceptions.rb +8 -0
- data/lib/versus/file.rb +157 -0
- data/lib/versus/file/jeweler_format.rb +49 -0
- data/lib/versus/file/plain_format.rb +39 -0
- data/lib/versus/number.rb +516 -0
- data/lib/versus/resolver.rb +303 -0
- metadata +124 -0
data/.index
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
type: ruby
|
3
|
+
revision: 2013
|
4
|
+
sources:
|
5
|
+
- Index.yml
|
6
|
+
authors:
|
7
|
+
- name: trans
|
8
|
+
email: transfire@gmail.com
|
9
|
+
- name: postmodern
|
10
|
+
website: http://trans.github.com
|
11
|
+
organizations: []
|
12
|
+
requirements:
|
13
|
+
- groups:
|
14
|
+
- test
|
15
|
+
development: true
|
16
|
+
name: qed
|
17
|
+
- groups:
|
18
|
+
- test
|
19
|
+
development: true
|
20
|
+
name: ae
|
21
|
+
conflicts: []
|
22
|
+
alternatives: []
|
23
|
+
resources:
|
24
|
+
- type: homepage
|
25
|
+
uri: http://dotruby.github.com
|
26
|
+
label: Homepage
|
27
|
+
- type: source
|
28
|
+
uri: http://github.com/dotruby/version
|
29
|
+
label: Source Code
|
30
|
+
repositories: []
|
31
|
+
categories: []
|
32
|
+
paths:
|
33
|
+
load:
|
34
|
+
- lib
|
35
|
+
copyrights:
|
36
|
+
- holder: Rubyworks
|
37
|
+
year: 2011
|
38
|
+
license: BSD-2-Clause
|
39
|
+
name: versus
|
40
|
+
title: Versus
|
41
|
+
version: 0.1.0
|
42
|
+
summary: Best-of-breed Version Class Library
|
43
|
+
description: The Versus gem provides a solid Version class along with supporting functionality,
|
44
|
+
such as version constratints and version dependency resolution.
|
45
|
+
date: '2013-01-05'
|
data/.yardopts
ADDED
data/HISTORY.md
ADDED
data/Index.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
name:
|
3
|
+
versus
|
4
|
+
|
5
|
+
version:
|
6
|
+
0.1.0
|
7
|
+
|
8
|
+
title:
|
9
|
+
Versus
|
10
|
+
|
11
|
+
summary:
|
12
|
+
Best-of-breed Version Class Library
|
13
|
+
|
14
|
+
description:
|
15
|
+
The Versus gem provides a solid Version class along with supporting
|
16
|
+
functionality, such as version constratints and version dependency
|
17
|
+
resolution.
|
18
|
+
|
19
|
+
requirements:
|
20
|
+
- qed (test)
|
21
|
+
- ae (test)
|
22
|
+
|
23
|
+
authors:
|
24
|
+
- name: trans
|
25
|
+
email: transfire@gmail.com
|
26
|
+
- name: postmodern
|
27
|
+
website: 'http://trans.github.com'
|
28
|
+
|
29
|
+
resources:
|
30
|
+
homepage: http://dotruby.github.com
|
31
|
+
source: http://github.com/dotruby/version
|
32
|
+
|
33
|
+
copyrights:
|
34
|
+
- year: 2011
|
35
|
+
holder: Rubyworks
|
36
|
+
license: BSD-2-Clause
|
37
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
BSD-2-Clause License
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
1. Redistributions of source code must retain the above copyright notice,
|
7
|
+
this list of conditions and the following disclaimer.
|
8
|
+
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
11
|
+
documentation and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
16
|
+
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
17
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
19
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
20
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
21
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
22
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
[Homepage](http://rubyworks.github.com/versus) /
|
2
|
+
[Report Issue](http://github.com/rubyworks/versus) /
|
3
|
+
[Source Code](http://github.com/rubyworks/versus)
|
4
|
+
( )
|
5
|
+
|
6
|
+
|
7
|
+
# [Versus](http://rubyworks.github.com/versus)
|
8
|
+
|
9
|
+
*A Best-of-Breed Version Class Library*
|
10
|
+
|
11
|
+
The Versus gem is a best-of-breed Version class library, providing classes
|
12
|
+
for a number of version related requirements, form `Version::Number` to
|
13
|
+
`Version::Resolution`.
|
14
|
+
|
15
|
+
|
16
|
+
## Overview
|
17
|
+
|
18
|
+
The primary class of the Versus gem is the `Version::Number` class. It does
|
19
|
+
exactly what one would expect, by taking a version literal and giving it a
|
20
|
+
versitle interface to query and manipulate.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
v = Version::Number.new('1.2.0')
|
24
|
+
v.major #=> 1
|
25
|
+
v.minor #=> 2
|
26
|
+
v.patch #=> 0
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
## Documentation
|
31
|
+
|
32
|
+
Versus uses QED to provided tested [demonstrations](http://). This provides a end-user
|
33
|
+
acceptance testing while also providing very readable documentation.
|
34
|
+
|
35
|
+
For API documentation checkout the YARD generated docs at [RubyDoc.Info](http://rubydoc.info/gems/versus/frames).
|
36
|
+
|
37
|
+
|
38
|
+
## Copyrights
|
39
|
+
|
40
|
+
Versus is copyrighted open source software.
|
41
|
+
|
42
|
+
Copyright 2011 Rubyworks
|
43
|
+
|
44
|
+
Versus can be modified and redistributed in accordance with the
|
45
|
+
[BSD-2-Clause](http://spdx.org/licenses/bsd-2-clause) License.
|
46
|
+
|
data/demo/applique/ae.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'versus'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
## Version::Constraint#initialize
|
2
|
+
|
3
|
+
The Constraint class models a single version equality
|
4
|
+
or inequality. It consists of the operator and the version
|
5
|
+
number.
|
6
|
+
|
7
|
+
c = Version::Constraint.new(['>=', '1.0'])
|
8
|
+
|
9
|
+
c.operator == '>='
|
10
|
+
c.number == '1.0'
|
11
|
+
|
12
|
+
### Using []
|
13
|
+
|
14
|
+
c = Version::Constraint['>=', '1.0']
|
15
|
+
|
16
|
+
c.operator == '>='
|
17
|
+
c.number == '1.0'
|
18
|
+
|
19
|
+
### String Parsing
|
20
|
+
|
21
|
+
The constraint constructor can also parse strings.
|
22
|
+
|
23
|
+
check do |mp|
|
24
|
+
mp.each do |str, (op, num)|
|
25
|
+
c = Version::Constraint.new(str)
|
26
|
+
c.operator.should == op
|
27
|
+
c.number.to_s.should == num
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ok '1.2.3' => ['==', '1.2.3']
|
32
|
+
ok '= 4.6.2' => ['==', '4.6.2']
|
33
|
+
ok '== 5.1.1' => ['==', '5.1.1']
|
34
|
+
ok '>= 2.3.4' => ['>=', '2.3.4']
|
35
|
+
ok '> 3.4.5' => ['>', '3.4.5']
|
36
|
+
ok '<= 2.3.4' => ['<=', '2.3.4']
|
37
|
+
ok '< 3.4.5' => ['<', '3.4.5']
|
38
|
+
|
39
|
+
Suffix notations are also parsable.
|
40
|
+
|
41
|
+
ok '1.2+' => ['>=', '1.2']
|
42
|
+
ok '1.3-' => ['<' , '1.3']
|
43
|
+
ok '2.8~' => ['=~', '2.8']
|
44
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
## Version#to_gem_version
|
2
|
+
|
3
|
+
Since RubyGems supporst a more limited version constrain format, the
|
4
|
+
Constraint class provides the `#to_gem_version` method to produce
|
5
|
+
a string representation of the constraint that RubyGems can understand.
|
6
|
+
|
7
|
+
version = Version::Constraint.parse('1.2~')
|
8
|
+
|
9
|
+
version.to_gem_version.should == "~> 1.2"
|
10
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
## Version::Number#initialize
|
2
|
+
|
3
|
+
A version number is composed of segments.
|
4
|
+
|
5
|
+
v = Version::Number.new(1,2,3,'alpha',4)
|
6
|
+
|
7
|
+
There a few alternative initializers. The most consice is [].
|
8
|
+
|
9
|
+
v = Version::Number[1,2,3,'beta',4]
|
10
|
+
|
11
|
+
The #new constructor can also take a string representation of the version.
|
12
|
+
|
13
|
+
v = Version::Number.new('1.2.3rc1')
|
14
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
## Version::Number.parse
|
2
|
+
|
3
|
+
The `parse` method ...
|
4
|
+
|
5
|
+
A String
|
6
|
+
|
7
|
+
v = Version::Number.parse('1.2.3')
|
8
|
+
|
9
|
+
v.to_s.assert == '1.2.3'
|
10
|
+
|
11
|
+
An Array
|
12
|
+
|
13
|
+
v = Version::Number.parse([1,2,3])
|
14
|
+
|
15
|
+
v.to_s.assert == '1.2.3'
|
16
|
+
|
17
|
+
Another Version::Number object
|
18
|
+
|
19
|
+
v1 = Version::Number.parse('2.5.6')
|
20
|
+
v2 = Version::Number.parse(v1)
|
21
|
+
|
22
|
+
v2.to_s.assert == '2.5.6'
|
23
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
## Version::Number#crush?
|
2
|
+
|
3
|
+
A version can be represented as a string in one of two ways --either
|
4
|
+
as a strict point seprated tuple or *crushed* where string segements
|
5
|
+
are merged with the following numerical segement.
|
6
|
+
|
7
|
+
The Version::Number class will automatically reqcognize a *crushed*
|
8
|
+
version if a segment of the version tuple is provided as such.
|
9
|
+
|
10
|
+
v = Version::Number.new(1,2,3,'alpha4')
|
11
|
+
|
12
|
+
v.assert.crush?
|
13
|
+
|
14
|
+
The output result of a crushed version.
|
15
|
+
|
16
|
+
v.to_s.assert == '1.2.3alpha4'
|
17
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
## Version::Number#build
|
2
|
+
|
3
|
+
The `build` method ...
|
4
|
+
|
5
|
+
v = Version::Number[1,2,3]
|
6
|
+
|
7
|
+
v.build.should == nil
|
8
|
+
|
9
|
+
|
10
|
+
v = Version::Number[1,2,3,'pre']
|
11
|
+
|
12
|
+
v.build.should == 'pre'
|
13
|
+
|
14
|
+
|
15
|
+
v = Version::Number[1,2,3,'pre',2]
|
16
|
+
|
17
|
+
v.build.should == 'pre.2'
|
18
|
+
|
19
|
+
|
20
|
+
v = Version::Number[1,2,3,'20101020']
|
21
|
+
|
22
|
+
v.build.should == '20101020'
|
23
|
+
|
@@ -0,0 +1,100 @@
|
|
1
|
+
## Version::Number#<=>
|
2
|
+
|
3
|
+
The inclusion of Comparable mixin into the Version class
|
4
|
+
along with the definition of #<=>, provides the class with
|
5
|
+
all the common inequality methods.
|
6
|
+
|
7
|
+
### Equality
|
8
|
+
|
9
|
+
check do |n1, n2|
|
10
|
+
v1 = Version::Number.parse(n1)
|
11
|
+
v2 = Version::Number.parse(n2)
|
12
|
+
v1 == v2
|
13
|
+
end
|
14
|
+
|
15
|
+
ok '1.0.0', '1.0.0'
|
16
|
+
ok '1.0.0', '1.0'
|
17
|
+
|
18
|
+
### Greater-Than
|
19
|
+
|
20
|
+
check do |n1, n2|
|
21
|
+
v1 = Version::Number.parse(n1)
|
22
|
+
v2 = Version::Number.parse(n2)
|
23
|
+
v1 > v2
|
24
|
+
end
|
25
|
+
|
26
|
+
ok '1.0.1', '1.0.0'
|
27
|
+
ok '1.1.0', '1.0.0'
|
28
|
+
ok '2.0.0', '1.0.0'
|
29
|
+
ok '1.1', '1.0.0'
|
30
|
+
ok '1.0.0', '1.0.0.rc.3'
|
31
|
+
|
32
|
+
no '1.0.0', '1.0.0'
|
33
|
+
|
34
|
+
### Less-Than
|
35
|
+
|
36
|
+
check do |n1, n2|
|
37
|
+
v1 = Version::Number.parse(n1)
|
38
|
+
v2 = Version::Number.parse(n2)
|
39
|
+
v1 < v2
|
40
|
+
end
|
41
|
+
|
42
|
+
ok '1.0.1', '1.0.2'
|
43
|
+
ok '1.1.0', '1.2.0'
|
44
|
+
ok '2.0.0', '2.1.0'
|
45
|
+
ok '1.2.3', '2.0.0'
|
46
|
+
ok '1.2.3', '2.0'
|
47
|
+
ok '1.1', '1.2.0'
|
48
|
+
ok '1.0.0.rc.2', '1.0.0'
|
49
|
+
|
50
|
+
no '1.0.0', '1.0.0'
|
51
|
+
|
52
|
+
### Greater-Than-Or-Equal
|
53
|
+
|
54
|
+
check do |n1, n2|
|
55
|
+
v1 = Version::Number.parse(n1)
|
56
|
+
v2 = Version::Number.parse(n2)
|
57
|
+
v1 >= v2
|
58
|
+
end
|
59
|
+
|
60
|
+
ok '1.0.1', '1.0.0'
|
61
|
+
ok '1.1.0', '1.0.0'
|
62
|
+
ok '2.0.0', '1.0.0'
|
63
|
+
ok '1.1', '1.0.0'
|
64
|
+
ok '1.0.0', '1.0.0.rc.3'
|
65
|
+
ok '1.0.0', '1.0.0'
|
66
|
+
|
67
|
+
### Less-Than-Or-Equal
|
68
|
+
|
69
|
+
check do |n1, n2|
|
70
|
+
v1 = Version::Number.parse(n1)
|
71
|
+
v2 = Version::Number.parse(n2)
|
72
|
+
v1 <= v2
|
73
|
+
end
|
74
|
+
|
75
|
+
ok '1.0.1', '1.0.2'
|
76
|
+
ok '1.1.0', '1.2.0'
|
77
|
+
ok '2.0.0', '2.1.0'
|
78
|
+
ok '1.1', '1.2.0'
|
79
|
+
ok '1.0.0', '1.0.0'
|
80
|
+
|
81
|
+
ok '1.0.0.rc.2', '1.0.0'
|
82
|
+
|
83
|
+
### Approximate Constraint
|
84
|
+
|
85
|
+
check do |n1, n2|
|
86
|
+
v1 = Version::Number.parse(n1)
|
87
|
+
v2 = Version::Number.parse(n2)
|
88
|
+
v1 =~ v2
|
89
|
+
end
|
90
|
+
|
91
|
+
ok '1.0.0', '1.0'
|
92
|
+
ok '1.0.2', '1.0'
|
93
|
+
ok '2.1.1', '2.1'
|
94
|
+
|
95
|
+
no '1.1.0', '1.2.0'
|
96
|
+
no '1.1.0', '2.0'
|
97
|
+
|
98
|
+
# TODO: Should this be ok ?
|
99
|
+
no '1.0.0.rc.2', '1.0'
|
100
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
## Version::Number Segments
|
2
|
+
|
3
|
+
A version number is divided up into segements, or *points*.
|
4
|
+
Some of the points have names. THe first three are widely known
|
5
|
+
as the *major*, *minor* and *patch* numbers, respectively.
|
6
|
+
|
7
|
+
v = Version::Number[1,2,3]
|
8
|
+
|
9
|
+
v.major.assert == 1
|
10
|
+
v.minor.assert == 2
|
11
|
+
v.patch.assert == 3
|
12
|
+
|
13
|
+
The Version::Number class also recognizes state, or status.
|
14
|
+
|
15
|
+
v = Version::Number[1,2,3,'beta',4]
|
16
|
+
|
17
|
+
v.state.assert == 'beta'
|
18
|
+
v.status.assert == 'beta'
|
19
|
+
|
20
|
+
From the state on is considered the *build* portion of the version.
|
21
|
+
|
22
|
+
v.build.assert == 'beta.4'
|
23
|
+
|
24
|
+
The *build number* is the number directly following the state.
|
25
|
+
|
26
|
+
v.build_number.assert == 4
|
27
|
+
|
28
|
+
While it is not recommended, technically the Version::Number class
|
29
|
+
can handle an arbitrarily long tuple.
|
30
|
+
|
31
|
+
v = Version::Number[1,2,3,4,5,6,'beta',7]
|
32
|
+
|
33
|
+
v.major.assert == 1
|
34
|
+
v.minor.assert == 2
|
35
|
+
v.patch.assert == 3
|
36
|
+
|
37
|
+
v.state.assert == 'beta'
|
38
|
+
|
39
|
+
However, there are no recognized names for the segments between
|
40
|
+
the third, patch entry and the state entry.
|
41
|
+
|
42
|
+
Short version can also be used.
|
43
|
+
|
44
|
+
v = Version::Number[1,'rc',7]
|
45
|
+
|
46
|
+
v.major.assert == 1
|
47
|
+
v.minor.assert == nil
|
48
|
+
v.patch.assert == nil
|
49
|
+
|
50
|
+
v.state.assert == 'rc'
|
51
|
+
|