version_utils 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/version_compare.rb +79 -0
- data/lib/version_format.rb +26 -0
- data/lib/version_manipulation.rb +71 -0
- data/lib/version_parse.rb +38 -0
- data/lib/version_utils.rb +8 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7b159b30245012b187e4661aed1c74409d08625acd84b1b828821a2bd89c5579
|
4
|
+
data.tar.gz: 34834acbaf68db94bacb66103605363069d5cdbf6747e9f18131ad50994da0c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9c2ab7546d56cc44cccb9e2803d0cf956169fc02fe02a118eb8d6bad7b4dd53edef89c591a6da417817d49f39824f5e4a74520d7090a76279e4602c35d162c7
|
7
|
+
data.tar.gz: c4efd4605805567075f73dc33b8a27af1f9e9cea98f89d62414be4923f68a59d8329b0e3561009bee22f1ab1b14a808807bc2685c86823f821b6bb47914ac0d2
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module VersionUtils
|
2
|
+
|
3
|
+
|
4
|
+
def self.compare(v1, v2)
|
5
|
+
|
6
|
+
v1 = self.parse(v1)
|
7
|
+
v2 = self.parse(v2)
|
8
|
+
|
9
|
+
compare_major = self.compare_segment(v1[:major], v2[:major])
|
10
|
+
if compare_major != 0
|
11
|
+
return compare_major
|
12
|
+
end
|
13
|
+
|
14
|
+
compare_minor = self.compare_segment(v1[:minor], v2[:minor])
|
15
|
+
if compare_minor != 0
|
16
|
+
return compare_minor
|
17
|
+
end
|
18
|
+
|
19
|
+
compare_patch = self.compare_segment(v1[:patch], v2[:patch])
|
20
|
+
if compare_patch != 0
|
21
|
+
return compare_patch
|
22
|
+
end
|
23
|
+
|
24
|
+
return self.compare_pre_releae(v1[:pre_release], v2[:pre_release])
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.compare_segment(s1, s2)
|
29
|
+
if s1 == nil
|
30
|
+
return -1
|
31
|
+
end
|
32
|
+
|
33
|
+
if s2 == nil
|
34
|
+
return 1
|
35
|
+
end
|
36
|
+
|
37
|
+
if s1 == s2
|
38
|
+
return 0
|
39
|
+
end
|
40
|
+
|
41
|
+
if s1 < s2
|
42
|
+
return -1
|
43
|
+
end
|
44
|
+
|
45
|
+
if s1 > s2
|
46
|
+
return 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.compare_pre_releae(pr1, pr2)
|
51
|
+
|
52
|
+
if pr1 == nil && pr2 == nil
|
53
|
+
return 0
|
54
|
+
end
|
55
|
+
|
56
|
+
if pr1 == nil && pr2 != nil
|
57
|
+
return 1
|
58
|
+
end
|
59
|
+
|
60
|
+
if pr1 != nil && pr2 == nil
|
61
|
+
return -1
|
62
|
+
end
|
63
|
+
|
64
|
+
pr1 = pr1.gsub(".", "")
|
65
|
+
pr2 = pr2.gsub(".", "")
|
66
|
+
|
67
|
+
if pr1 == pr2
|
68
|
+
return 0
|
69
|
+
end
|
70
|
+
|
71
|
+
if pr1 > pr2
|
72
|
+
return 1
|
73
|
+
end
|
74
|
+
|
75
|
+
if pr1 < pr2
|
76
|
+
return -1
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module VersionUtils
|
2
|
+
def self.format(parts)
|
3
|
+
version = []
|
4
|
+
version = version + [parts[:major]]
|
5
|
+
|
6
|
+
if parts[:minor] != nil
|
7
|
+
version = version + [parts[:minor]]
|
8
|
+
end
|
9
|
+
|
10
|
+
if parts[:patch] != nil
|
11
|
+
version = version + [parts[:patch]]
|
12
|
+
end
|
13
|
+
|
14
|
+
version = version.join(".")
|
15
|
+
|
16
|
+
if parts[:pre_release] != nil
|
17
|
+
version = version + "-" + parts[:pre_release]
|
18
|
+
end
|
19
|
+
|
20
|
+
if parts[:metadata] != nil
|
21
|
+
version = version + "+" + parts[:metadata]
|
22
|
+
end
|
23
|
+
|
24
|
+
return version.force_encoding("utf-8")
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module VersionUtils
|
2
|
+
def self.upgrade_major(
|
3
|
+
version,
|
4
|
+
update_build_version: false)
|
5
|
+
|
6
|
+
version = self.parse(version)
|
7
|
+
|
8
|
+
version[:major] += 1
|
9
|
+
|
10
|
+
if version[:minor] != nil
|
11
|
+
version[:minor] = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
version = self.update_patch(version)
|
15
|
+
version = self.update_pre_release(version)
|
16
|
+
version = self.update_metadata(version, update_build_version)
|
17
|
+
|
18
|
+
return self.format(version)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.upgrade_minor(
|
22
|
+
version,
|
23
|
+
update_build_version: false)
|
24
|
+
version = self.parse(version)
|
25
|
+
|
26
|
+
version[:minor] += 1
|
27
|
+
|
28
|
+
version = self.update_patch(version)
|
29
|
+
version = self.update_pre_release(version)
|
30
|
+
version = self.update_metadata(version, update_build_version)
|
31
|
+
return self.format(version)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.upgrade_patch(
|
35
|
+
version,
|
36
|
+
update_build_version: false)
|
37
|
+
version = self.parse(version)
|
38
|
+
|
39
|
+
version[:patch] += 1
|
40
|
+
|
41
|
+
version = self.update_pre_release(version)
|
42
|
+
version = self.update_metadata(version, update_build_version)
|
43
|
+
return self.format(version)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.update_patch(version)
|
47
|
+
if version[:patch] != nil
|
48
|
+
version[:patch] = 0
|
49
|
+
end
|
50
|
+
return version
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.update_pre_release(version)
|
54
|
+
version[:pre_release] = nil
|
55
|
+
return version
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.update_metadata(version, update_build_version)
|
59
|
+
if update_build_version
|
60
|
+
begin
|
61
|
+
build_version = Integer(version[:metadata])
|
62
|
+
version[:metadata] = (build_version + 1).to_s
|
63
|
+
rescue
|
64
|
+
version[:metadata] = nil
|
65
|
+
end
|
66
|
+
else
|
67
|
+
version[:metadata] = nil
|
68
|
+
end
|
69
|
+
return version
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module VersionUtils
|
2
|
+
def self.parse(version)
|
3
|
+
|
4
|
+
result = {}
|
5
|
+
|
6
|
+
if version.split("+").length > 1
|
7
|
+
metadata = version.split("+")[1]
|
8
|
+
result[:metadata] = metadata
|
9
|
+
version = version.split("+")[0]
|
10
|
+
end
|
11
|
+
|
12
|
+
if version.split("-").length > 1
|
13
|
+
part_post_segments = version.split("-")[1]
|
14
|
+
pre_release = part_post_segments.split("+")[0]
|
15
|
+
result[:pre_release] = pre_release
|
16
|
+
version = version.split("-")[0]
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
segments = version.split(".")
|
21
|
+
|
22
|
+
result[:major] = Integer(segments[0])
|
23
|
+
|
24
|
+
if segments.length > 1
|
25
|
+
result[:minor] = Integer(segments[1])
|
26
|
+
else
|
27
|
+
result[:minor] = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
if segments.length > 2
|
31
|
+
result[:patch] = Integer(segments[2])
|
32
|
+
else
|
33
|
+
result[:patch] = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
return result
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: version_utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jesus Serrano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- dev@onepointzero.org
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/version_compare.rb
|
21
|
+
- lib/version_format.rb
|
22
|
+
- lib/version_manipulation.rb
|
23
|
+
- lib/version_parse.rb
|
24
|
+
- lib/version_utils.rb
|
25
|
+
homepage: https://github.com/Tyrbok/version_utils
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubygems_version: 3.0.8
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Utils for version-strings manipulation
|
48
|
+
test_files: []
|