vmlib 1.0.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.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/README.md +80 -0
- data/Rakefile +24 -0
- data/Version +1 -0
- data/bin/vmlib +156 -0
- data/lib/vmlib/base.rb +214 -0
- data/lib/vmlib/bump.rb +93 -0
- data/lib/vmlib/compare.rb +107 -0
- data/lib/vmlib/errors.rb +55 -0
- data/lib/vmlib/file.rb +106 -0
- data/lib/vmlib/format.rb +94 -0
- data/lib/vmlib/issue.txt +13 -0
- data/lib/vmlib/parse.rb +216 -0
- data/lib/vmlib/source.rb +65 -0
- data/lib/vmlib/version.rb +12 -0
- data/lib/vmlib.rb +23 -0
- data/test/test_version_basic.rb +113 -0
- data/vmlib.gemspec +26 -0
- metadata +91 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 59fe12924831b9a814d93ead77137e7ec9ef03ce
|
|
4
|
+
data.tar.gz: 89c6f9f26768d373ef1fb8381653e3e92c3b6dc2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a09e8f0656391ed990283f1cc884a203ea9d4b48ef69adc2fc300e902b4a4e5b6a19d3e23a54476b1fcde7e9cb692d814f8a6cb246892c061c24cf10dc3ffc90
|
|
7
|
+
data.tar.gz: 2e1f5938fd9cae969f29a62be0b7e36492059318549dcff805e66c9e0ce8c2101b28fa9b1983ab6540229fde0d6616fecebe3a6e6c138d292f45d5dd8edcd06d
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Version Manager Library
|
|
2
|
+
=======================
|
|
3
|
+
|
|
4
|
+
The Version manager library (VMLib) is a generic library to handle
|
|
5
|
+
semantic versioning as specified at <http://semver.org>. In addition to
|
|
6
|
+
complying with semantic versioning v2.0.0-rc.1, it adds additional API
|
|
7
|
+
calls to bump the major, minor and patch versions as well as handle
|
|
8
|
+
distinct types of releases (development, alpha, beta, release candidate,
|
|
9
|
+
final as well as a custom type)
|
|
10
|
+
|
|
11
|
+
# Public API
|
|
12
|
+
|
|
13
|
+
VMLib has the following public CLI interface
|
|
14
|
+
|
|
15
|
+
`init <name>` - Initializes the version tracker
|
|
16
|
+
> This creates a new version tracker library for the project named
|
|
17
|
+
> <name>. It initializes the version number to 0.1.0 and the release
|
|
18
|
+
> type to `:development` and the release number to 0. If the project
|
|
19
|
+
> has already been intialized, then raises VMLibInitError.
|
|
20
|
+
|
|
21
|
+
`bump major` - Bumps the major version
|
|
22
|
+
> This will increment the major version by 1, while simultaneously
|
|
23
|
+
> setting the minor version and patchlevel to 0.
|
|
24
|
+
|
|
25
|
+
`bump minor` - Bumps the minor version
|
|
26
|
+
> This will increment the minor version by 1 and reset the patch level
|
|
27
|
+
> to 0.
|
|
28
|
+
|
|
29
|
+
`bump patch` - Bumps the patch level
|
|
30
|
+
> This will increment the patch level by 1.
|
|
31
|
+
|
|
32
|
+
`bump type` - Bumps the prerelease type to the next higher release type
|
|
33
|
+
> This will bump the prerelease type up to the next higher release type,
|
|
34
|
+
> i.e., `development` -> `alpha` -> `beta` -> `release candidate` ->
|
|
35
|
+
> `final`. The corresponding release number is also set to 1. If the
|
|
36
|
+
> release type is already `final` or `custom`, it will raise
|
|
37
|
+
> `VMLib::Errors::BumpError`.
|
|
38
|
+
|
|
39
|
+
`bump pre`, `bump prerelease`
|
|
40
|
+
> This will bump the release number by 1 if the prerelease type is
|
|
41
|
+
> `development`, `alpha`, `beta` or `release candidate`. If the
|
|
42
|
+
> release type is `:final` it will raise VMLib::Errors::BumpError.
|
|
43
|
+
> If the release type is `custom`, it will take the last field of
|
|
44
|
+
> `relcustom` and if numeric, it will bump it, otherwise, it will
|
|
45
|
+
> raise VMLib::Errors::BumpError.
|
|
46
|
+
|
|
47
|
+
`set pre`, `set prerelease`
|
|
48
|
+
> This will set the prerelease information as specified by the user.
|
|
49
|
+
|
|
50
|
+
`set build`
|
|
51
|
+
> This will set the build information as specified by the user.
|
|
52
|
+
|
|
53
|
+
`format`
|
|
54
|
+
> This takes in an optional format string for printing the version
|
|
55
|
+
> information. If the format string is not specified, it will revert to
|
|
56
|
+
> the default, however, if the format string is `tag`, then it will
|
|
57
|
+
> print the tag format.
|
|
58
|
+
|
|
59
|
+
`update`
|
|
60
|
+
> This command will search for all source files beginning with the
|
|
61
|
+
> string `version` and will update them to match with the primary
|
|
62
|
+
> version number set by the bump routine. It will also generate a Git
|
|
63
|
+
> commit for the changed files.
|
|
64
|
+
|
|
65
|
+
`tag`
|
|
66
|
+
> This command will generate a Git tag with the version specified by the
|
|
67
|
+
> version number file.
|
|
68
|
+
|
|
69
|
+
# Release Types
|
|
70
|
+
|
|
71
|
+
VMLib supports the following release types, in order
|
|
72
|
+
|
|
73
|
+
* development
|
|
74
|
+
* alpha
|
|
75
|
+
* beta
|
|
76
|
+
* release candidate
|
|
77
|
+
* final
|
|
78
|
+
* custom
|
|
79
|
+
|
|
80
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# VMLib Rakefile
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
|
|
5
|
+
require "bundler/gem_tasks"
|
|
6
|
+
require "vmlib/version"
|
|
7
|
+
|
|
8
|
+
# Unit tests task
|
|
9
|
+
desc "Run unit test task for vmlib-#{VMLib::VERSION}"
|
|
10
|
+
task :test do
|
|
11
|
+
$:.unshift(::File.expand_path('lib', ::File.dirname(__FILE__)))
|
|
12
|
+
if ::ENV['TEST_CASE']
|
|
13
|
+
test_files = ::Dir.glob("test/#{::ENV['TEST_CASE']}.rb")
|
|
14
|
+
else
|
|
15
|
+
test_files = ::Dir.glob("test/**/test_*.rb")
|
|
16
|
+
end
|
|
17
|
+
$VERBOSE = true
|
|
18
|
+
|
|
19
|
+
test_files.each do |path|
|
|
20
|
+
load path
|
|
21
|
+
puts "Loaded testcase #{path}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
data/Version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
vmlib 1.0.0
|
data/bin/vmlib
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# -*- ruby -*-
|
|
3
|
+
|
|
4
|
+
require 'vmlib'
|
|
5
|
+
|
|
6
|
+
module VMLib
|
|
7
|
+
|
|
8
|
+
# Raised when there is an issue on the command line
|
|
9
|
+
class CommandError < Errors::VMLibError; end
|
|
10
|
+
|
|
11
|
+
###########################################################################
|
|
12
|
+
# Command line interface to VMLib gem
|
|
13
|
+
###########################################################################
|
|
14
|
+
begin
|
|
15
|
+
command = ARGV.shift || 'format'
|
|
16
|
+
|
|
17
|
+
case command
|
|
18
|
+
|
|
19
|
+
#########################################################################
|
|
20
|
+
# Initializes a new version file in the current folder
|
|
21
|
+
#########################################################################
|
|
22
|
+
when /^init(?:ialize)?$/ # init | initialize
|
|
23
|
+
name = ARGV.shift or
|
|
24
|
+
raise CommandError, "required: <name>"
|
|
25
|
+
|
|
26
|
+
vfile = File.new
|
|
27
|
+
vfile.create(name)
|
|
28
|
+
|
|
29
|
+
#########################################################################
|
|
30
|
+
# Bumps the specified version field by 1
|
|
31
|
+
# If type is specified, then bumps the type to the next higher type, i.e.
|
|
32
|
+
# development -> alpha -> beta -> release candidate -> final
|
|
33
|
+
#########################################################################
|
|
34
|
+
when 'bump' # bump
|
|
35
|
+
dimension = ARGV.shift or
|
|
36
|
+
raise CommandError, "required: major | minor | patch | pre | type"
|
|
37
|
+
|
|
38
|
+
vfile = File.new
|
|
39
|
+
version = vfile.read
|
|
40
|
+
|
|
41
|
+
case dimension
|
|
42
|
+
when 'major'
|
|
43
|
+
version.bump_major
|
|
44
|
+
when 'minor'
|
|
45
|
+
version.bump_minor
|
|
46
|
+
when 'patch'
|
|
47
|
+
version.bump_patch
|
|
48
|
+
when 'pre'
|
|
49
|
+
version.bump_prerelease
|
|
50
|
+
when 'type'
|
|
51
|
+
version.bump_release_type
|
|
52
|
+
else
|
|
53
|
+
raise CommandError, "invalid dimension #{dimension}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
puts "Bumped version to #{version.tag}"
|
|
57
|
+
vfile.write version
|
|
58
|
+
|
|
59
|
+
#########################################################################
|
|
60
|
+
# Sets either the prerelease or the build string
|
|
61
|
+
#########################################################################
|
|
62
|
+
when 'set' # set pre | prerelease | build
|
|
63
|
+
type = ARGV.shift or
|
|
64
|
+
raise CommandError, "required: pre[release] | build"
|
|
65
|
+
|
|
66
|
+
case type
|
|
67
|
+
when /^pre(?:release)?$/ # pre | prerelease
|
|
68
|
+
pre = ARGV.shift or
|
|
69
|
+
raise CommandError, "required: <prerelease string>"
|
|
70
|
+
|
|
71
|
+
vfile = File.new
|
|
72
|
+
version = vfile.read
|
|
73
|
+
version.prerelease = pre
|
|
74
|
+
puts "Set prerelease version to #{version.tag}"
|
|
75
|
+
vfile.write version
|
|
76
|
+
|
|
77
|
+
when 'build' # build
|
|
78
|
+
build = ARGV.shift or
|
|
79
|
+
raise CommandError, "required: <build string>"
|
|
80
|
+
|
|
81
|
+
vfile = File.new
|
|
82
|
+
version = vfile.read
|
|
83
|
+
version.build = build
|
|
84
|
+
puts "Set build version to #{version.tag}"
|
|
85
|
+
vfile.write version
|
|
86
|
+
|
|
87
|
+
else
|
|
88
|
+
raise CommandError, "unrecognized set type #{type}"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
#########################################################################
|
|
92
|
+
# Updates all the source files with the bumped version
|
|
93
|
+
# Also writes the changes to the git repository
|
|
94
|
+
#########################################################################
|
|
95
|
+
when 'update' # update
|
|
96
|
+
sfile = Source.new
|
|
97
|
+
sfile.update
|
|
98
|
+
version = File.new.read.tag
|
|
99
|
+
|
|
100
|
+
puts "Committing changed files in #{version}"
|
|
101
|
+
system("git commit -am 'Bumped version to #{version}'")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
#########################################################################
|
|
105
|
+
# Display the version as a format
|
|
106
|
+
# Accepts an optional format string or 'tag'. If neither is specified
|
|
107
|
+
# then it will print using the default format string %n%M.%m.%p%r%b
|
|
108
|
+
#########################################################################
|
|
109
|
+
when 'format'
|
|
110
|
+
fstr = ARGV.shift
|
|
111
|
+
version = File.new.read
|
|
112
|
+
|
|
113
|
+
if fstr.nil?
|
|
114
|
+
puts version.to_s
|
|
115
|
+
elsif fstr == 'tag'
|
|
116
|
+
puts version.tag
|
|
117
|
+
else
|
|
118
|
+
puts version.format fstr
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
#########################################################################
|
|
122
|
+
# Generates a tag version and creates a new Git tag
|
|
123
|
+
# For now, it simply prints out the tag string
|
|
124
|
+
#########################################################################
|
|
125
|
+
when 'tag'
|
|
126
|
+
version = File.new.read
|
|
127
|
+
puts "Tagging version #{version.tag}"
|
|
128
|
+
|
|
129
|
+
system "git tag -a -m '#{version.to_s}' #{version.tag}"
|
|
130
|
+
|
|
131
|
+
else
|
|
132
|
+
raise CommandError, "invalid command #{command}"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
###########################################################################
|
|
136
|
+
# Handler for errors on the command line
|
|
137
|
+
###########################################################################
|
|
138
|
+
rescue CommandError => e
|
|
139
|
+
puts "#{$0}: #{e.message}"
|
|
140
|
+
puts "Type #{$0} help for more info"
|
|
141
|
+
exit 1
|
|
142
|
+
|
|
143
|
+
###########################################################################
|
|
144
|
+
# Handler for errors from the VMLib source
|
|
145
|
+
###########################################################################
|
|
146
|
+
rescue Errors::VMLibError => e
|
|
147
|
+
puts "#{$0}: #{e.message}"
|
|
148
|
+
exit 1
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
###########################################################################
|
|
152
|
+
# No handler for other errors
|
|
153
|
+
###########################################################################
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
end
|
data/lib/vmlib/base.rb
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
# VMLib base
|
|
3
|
+
###############################################################################
|
|
4
|
+
# Copyright (C) 2013 Nirenjan Krishnan
|
|
5
|
+
# All rights reserved.
|
|
6
|
+
###############################################################################
|
|
7
|
+
|
|
8
|
+
;
|
|
9
|
+
|
|
10
|
+
module VMLib
|
|
11
|
+
|
|
12
|
+
# This is the primary version number class for the version manager library
|
|
13
|
+
class Version
|
|
14
|
+
|
|
15
|
+
# Reset the version number to 0.0.0-0
|
|
16
|
+
def reset
|
|
17
|
+
@name = ''
|
|
18
|
+
@major = 0
|
|
19
|
+
@minor = 0
|
|
20
|
+
@patch = 0
|
|
21
|
+
@reltype = :rel_type_dev
|
|
22
|
+
@devnum = 0
|
|
23
|
+
@alphanum = 0
|
|
24
|
+
@betanum = 0
|
|
25
|
+
@rcnum = 0
|
|
26
|
+
@relcustom = []
|
|
27
|
+
@buildtype = :bld_type_final
|
|
28
|
+
@buildcustom = []
|
|
29
|
+
|
|
30
|
+
true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Create a new version instance and set it to the specified parameters
|
|
34
|
+
def initialize(name = '', major = 0, minor = 0, patch = 0, prerelease = '0', build = '')
|
|
35
|
+
reset
|
|
36
|
+
set_name name
|
|
37
|
+
set_major major
|
|
38
|
+
set_minor minor
|
|
39
|
+
set_patch patch
|
|
40
|
+
set_prerelease prerelease
|
|
41
|
+
set_build build
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Inspect the version object
|
|
45
|
+
def inspect
|
|
46
|
+
str = "#<#{self.class}:"
|
|
47
|
+
str += "0x%016x" % (self.object_id * 2)
|
|
48
|
+
str += " @name='#{@name}'"
|
|
49
|
+
str += " @major=#{@major}"
|
|
50
|
+
str += " @minor=#{@minor}"
|
|
51
|
+
str += " @patch=#{@patch}"
|
|
52
|
+
|
|
53
|
+
case @reltype
|
|
54
|
+
when :rel_type_dev
|
|
55
|
+
str += " @devnum=#{@devnum}"
|
|
56
|
+
when :rel_type_alpha
|
|
57
|
+
str += " @alphanum=#{@alphanum}"
|
|
58
|
+
when :rel_type_beta
|
|
59
|
+
str += " @betanum=#{@betanum}"
|
|
60
|
+
when :rel_type_rc
|
|
61
|
+
str += " @rcnum=#{@rcnum}"
|
|
62
|
+
when :rel_type_custom
|
|
63
|
+
str += " @prerelease=#{@relcustom.inspect}"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
case @buildtype
|
|
67
|
+
when :bld_type_custom
|
|
68
|
+
str += " @build=#{@buildcustom.inspect}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
str += ">"
|
|
72
|
+
|
|
73
|
+
str
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
###########################################################################
|
|
77
|
+
# Accessor functions for name
|
|
78
|
+
###########################################################################
|
|
79
|
+
|
|
80
|
+
# The program or project name
|
|
81
|
+
attr_accessor :name
|
|
82
|
+
|
|
83
|
+
# Set the program or project name
|
|
84
|
+
undef name=
|
|
85
|
+
def name= (name) #:nodoc:
|
|
86
|
+
set_name name
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def set_name (name) #:nodoc:
|
|
90
|
+
name.kind_of? String or
|
|
91
|
+
raise Errors::AssignError, "invalid name #{name.inspect}"
|
|
92
|
+
|
|
93
|
+
@name = name
|
|
94
|
+
end
|
|
95
|
+
private :set_name
|
|
96
|
+
|
|
97
|
+
###########################################################################
|
|
98
|
+
# Accessor functions for major
|
|
99
|
+
###########################################################################
|
|
100
|
+
|
|
101
|
+
# The major version number
|
|
102
|
+
attr_accessor :major
|
|
103
|
+
|
|
104
|
+
# Set the major version number
|
|
105
|
+
undef major=
|
|
106
|
+
def major=(major) #:nodoc:
|
|
107
|
+
set_major major
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def set_major (major) #:nodoc:
|
|
111
|
+
major.kind_of? Integer or
|
|
112
|
+
raise Errors::AssignError, "invalid major version #{major.inspect}"
|
|
113
|
+
|
|
114
|
+
@major = major
|
|
115
|
+
end
|
|
116
|
+
private :set_major
|
|
117
|
+
|
|
118
|
+
###########################################################################
|
|
119
|
+
# Accessor functions for minor
|
|
120
|
+
###########################################################################
|
|
121
|
+
|
|
122
|
+
# The minor version number
|
|
123
|
+
attr_accessor :minor
|
|
124
|
+
|
|
125
|
+
# Set the minor version number
|
|
126
|
+
undef minor=
|
|
127
|
+
def minor=(minor) #:nodoc:
|
|
128
|
+
set_minor minor
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def set_minor (minor) #:nodoc:
|
|
132
|
+
minor.kind_of? Integer or
|
|
133
|
+
raise Errors::AssignError, "invalid minor version #{minor.inspect}"
|
|
134
|
+
|
|
135
|
+
@minor = minor
|
|
136
|
+
end
|
|
137
|
+
private :set_minor
|
|
138
|
+
|
|
139
|
+
###########################################################################
|
|
140
|
+
# Accessor functions for patch
|
|
141
|
+
###########################################################################
|
|
142
|
+
|
|
143
|
+
# The patch version number
|
|
144
|
+
attr_accessor :patch
|
|
145
|
+
|
|
146
|
+
# Set the patch version number
|
|
147
|
+
undef patch=
|
|
148
|
+
def patch=(patch) #:nodoc:
|
|
149
|
+
set_patch patch
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def set_patch (patch) #:nodoc:
|
|
153
|
+
patch.kind_of? Integer or
|
|
154
|
+
raise Errors::AssignError, "invalid patch version #{patch.inspect}"
|
|
155
|
+
|
|
156
|
+
@patch = patch
|
|
157
|
+
end
|
|
158
|
+
private :set_patch
|
|
159
|
+
|
|
160
|
+
###########################################################################
|
|
161
|
+
# Accessor functions for prerelease
|
|
162
|
+
###########################################################################
|
|
163
|
+
|
|
164
|
+
# Get the prerelease information
|
|
165
|
+
def prerelease #:attr:
|
|
166
|
+
format '%r'
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Set the prerelease information
|
|
170
|
+
def prerelease=(prerelease)
|
|
171
|
+
set_prerelease prerelease
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def set_prerelease (prerelease) #:nodoc:
|
|
175
|
+
prerelease.kind_of? String or
|
|
176
|
+
raise Errors::ParseError, "invalid prerelease #{prerelease.inspect}"
|
|
177
|
+
|
|
178
|
+
m = parse_release(prerelease)
|
|
179
|
+
prerelease = prerelease.sub(SPECIAL_REGEX, '') if m
|
|
180
|
+
warn "ignoring additional data #{prerelease.inspect}" unless prerelease.empty?
|
|
181
|
+
|
|
182
|
+
true
|
|
183
|
+
end
|
|
184
|
+
private :set_prerelease
|
|
185
|
+
|
|
186
|
+
###########################################################################
|
|
187
|
+
# Accessor functions for build
|
|
188
|
+
###########################################################################
|
|
189
|
+
|
|
190
|
+
# Get the build information
|
|
191
|
+
def build
|
|
192
|
+
format '%b'
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Set the build information
|
|
196
|
+
def build=(build)
|
|
197
|
+
set_build build
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def set_build (build) #:nodoc:
|
|
201
|
+
build.kind_of? String or
|
|
202
|
+
raise Errors::ParseError, "invalid build #{build.inspect}"
|
|
203
|
+
|
|
204
|
+
m = parse_build(build)
|
|
205
|
+
build = build.sub(SPECIAL_REGEX, '') if m
|
|
206
|
+
warn "ignoring additional data #{build.inspect}" unless build.empty?
|
|
207
|
+
|
|
208
|
+
true
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
end
|
data/lib/vmlib/bump.rb
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
# VMLib bump routines
|
|
3
|
+
###############################################################################
|
|
4
|
+
# Copyright (C) 2013 Nirenjan Krishnan
|
|
5
|
+
# All rights reserved.
|
|
6
|
+
###############################################################################
|
|
7
|
+
|
|
8
|
+
;
|
|
9
|
+
|
|
10
|
+
module VMLib
|
|
11
|
+
|
|
12
|
+
class Version
|
|
13
|
+
|
|
14
|
+
# Bump the major release by 1 and reset the minor and patch
|
|
15
|
+
# releases to 0.
|
|
16
|
+
def bump_major
|
|
17
|
+
@major = @major + 1
|
|
18
|
+
@minor = 0
|
|
19
|
+
@patch = 0
|
|
20
|
+
|
|
21
|
+
true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Bump the minor release by 1 and reset the patch release to 0
|
|
25
|
+
def bump_minor
|
|
26
|
+
@minor = @minor + 1
|
|
27
|
+
@patch = 0
|
|
28
|
+
|
|
29
|
+
true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Bump the patch release by 1
|
|
33
|
+
def bump_patch
|
|
34
|
+
@patch = @patch + 1
|
|
35
|
+
|
|
36
|
+
true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Bump the prerelease version by 1
|
|
40
|
+
def bump_prerelease
|
|
41
|
+
case @reltype
|
|
42
|
+
when :rel_type_dev
|
|
43
|
+
@devnum += 1
|
|
44
|
+
when :rel_type_alpha
|
|
45
|
+
@alphanum += 1
|
|
46
|
+
when :rel_type_beta
|
|
47
|
+
@betanum += 1
|
|
48
|
+
when :rel_type_rc
|
|
49
|
+
@rcnum += 1
|
|
50
|
+
when :rel_type_final
|
|
51
|
+
raise Errors::BumpError, "cannot bump prerelease for a final version"
|
|
52
|
+
when :rel_type_custom
|
|
53
|
+
lastfield = @relcustom.pop
|
|
54
|
+
if lastfield.kind_of? Integer
|
|
55
|
+
@relcustom.push (lastfield + 1)
|
|
56
|
+
else
|
|
57
|
+
@relcustom.push lastfield
|
|
58
|
+
raise Errors::BumpError, "cannot bump a non-numeric prerelease field"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Bump the prerelease type
|
|
64
|
+
def bump_release_type
|
|
65
|
+
case @reltype
|
|
66
|
+
when :rel_type_dev # development -> alpha
|
|
67
|
+
@reltype = :rel_type_alpha
|
|
68
|
+
@alphanum = 1
|
|
69
|
+
|
|
70
|
+
when :rel_type_alpha # alpha -> beta
|
|
71
|
+
@reltype = :rel_type_beta
|
|
72
|
+
@betanum = 1
|
|
73
|
+
|
|
74
|
+
when :rel_type_beta # beta -> rc
|
|
75
|
+
@reltype = :rel_type_rc
|
|
76
|
+
@rcnum = 1
|
|
77
|
+
|
|
78
|
+
when :rel_type_rc # rc -> final
|
|
79
|
+
@reltype = :rel_type_final
|
|
80
|
+
|
|
81
|
+
when :rel_type_final # ERROR!
|
|
82
|
+
raise Errors::BumpError, "cannot bump from final version"
|
|
83
|
+
|
|
84
|
+
when :rel_type_custom # ERROR!
|
|
85
|
+
raise Errors::BumpError, "cannot bump from custom prerelease"
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
# VMLib comparision routines
|
|
3
|
+
###############################################################################
|
|
4
|
+
# Copyright (C) 2013 Nirenjan Krishnan
|
|
5
|
+
# All rights reserved.
|
|
6
|
+
###############################################################################
|
|
7
|
+
|
|
8
|
+
;
|
|
9
|
+
|
|
10
|
+
module VMLib
|
|
11
|
+
|
|
12
|
+
class Version
|
|
13
|
+
|
|
14
|
+
# Compare two arrays element by element.
|
|
15
|
+
# If one element is numeric and the other a string, then the string
|
|
16
|
+
# takes precedence over the number.
|
|
17
|
+
def compare_arrays(array1, array2)
|
|
18
|
+
raise Errors::ParameterError unless array1.is_a? Array
|
|
19
|
+
raise Errors::ParameterError unless array2.is_a? Array
|
|
20
|
+
|
|
21
|
+
# Run for the shorter of the two arrays
|
|
22
|
+
if array1.length < array2.length
|
|
23
|
+
len = array1.length
|
|
24
|
+
possibly_gt = :array2
|
|
25
|
+
else
|
|
26
|
+
len = array2.length
|
|
27
|
+
possibly_gt = :array1
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
cmp = 0
|
|
31
|
+
|
|
32
|
+
# Check for an empty array, if so, resort to using the Array <=>
|
|
33
|
+
if len == 0
|
|
34
|
+
return array1 <=> array2
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
for i in (0...len)
|
|
38
|
+
elm1 = array1[i]
|
|
39
|
+
elm2 = array2[i]
|
|
40
|
+
|
|
41
|
+
cls1 = elm1.class
|
|
42
|
+
cls2 = elm2.class
|
|
43
|
+
|
|
44
|
+
if cls1 == cls2
|
|
45
|
+
cmp = (elm1 <=> elm2)
|
|
46
|
+
else
|
|
47
|
+
if cls1 == String # cls2 = Fixnum
|
|
48
|
+
# String > Fixnum
|
|
49
|
+
cmp = 1
|
|
50
|
+
else # cls1 = Fixnum, cls2 = String
|
|
51
|
+
# Fixnum < String
|
|
52
|
+
cmp = -1
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
break unless cmp == 0
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
return cmp unless cmp == 0
|
|
60
|
+
|
|
61
|
+
# Resort to comparing the remaining elements using Array <=>
|
|
62
|
+
cmp = (array1[len...array1.length] <=> array2[len...array2.length])
|
|
63
|
+
return cmp
|
|
64
|
+
end
|
|
65
|
+
private :compare_arrays
|
|
66
|
+
|
|
67
|
+
# Compare two version structures
|
|
68
|
+
def <=> (other)
|
|
69
|
+
# Check major version
|
|
70
|
+
cmp = (@major <=> other.major)
|
|
71
|
+
return cmp unless cmp == 0
|
|
72
|
+
|
|
73
|
+
# Check minor version
|
|
74
|
+
cmp = (@minor <=> other.minor)
|
|
75
|
+
return cmp unless cmp == 0
|
|
76
|
+
|
|
77
|
+
# Check patch version
|
|
78
|
+
cmp = (@patch <=> other.patch)
|
|
79
|
+
return cmp unless cmp == 0
|
|
80
|
+
|
|
81
|
+
# Check prerelease arrays
|
|
82
|
+
myown_pre = self.prerelease.split('.')
|
|
83
|
+
convert_to_integer(myown_pre)
|
|
84
|
+
other_pre = other.prerelease.split('.')
|
|
85
|
+
convert_to_integer(other_pre)
|
|
86
|
+
cmp = compare_arrays(myown_pre, other_pre)
|
|
87
|
+
|
|
88
|
+
# Make sure that the prerelease is compared correctly
|
|
89
|
+
cmp = 1 if cmp == -1 and myown_pre.length == 0
|
|
90
|
+
cmp = -1 if cmp == 1 and other_pre.length == 0
|
|
91
|
+
return cmp unless cmp == 0
|
|
92
|
+
|
|
93
|
+
# Check build arrays
|
|
94
|
+
myown_bld = self.build.split('.')
|
|
95
|
+
convert_to_integer(myown_bld)
|
|
96
|
+
other_bld = other.build.split('.')
|
|
97
|
+
convert_to_integer(other_bld)
|
|
98
|
+
cmp = compare_arrays(myown_bld, other_bld)
|
|
99
|
+
return cmp unless cmp == 0
|
|
100
|
+
|
|
101
|
+
return 0
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
end
|