deb_version 0.1.0 → 1.0.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
  SHA256:
3
- metadata.gz: a0eec3bd476766475cb472300c628c1ef1cf3b34141ef696e75df6a636d99952
4
- data.tar.gz: ae81bf2ff31ea9e2667a16ca7792346d0cac487ddfe01c998b7f3b08342b4416
3
+ metadata.gz: da683bbad0561bf83d9e53fb06c0c15b4e91f7a0d965a9896f9b2488b0aa075a
4
+ data.tar.gz: '061307976f05755c2a8aa14f3f25a9138b944f1385e30b85d30a4eea4f8edc90'
5
5
  SHA512:
6
- metadata.gz: 669966c3f74b9dd259e96c6c57b2dc56bdd3ea7785c0e0066ff7699fb62c730e871c9c8ce7b719b4e36060c198cc49363e04f31a99203280d31df9dadaf87458
7
- data.tar.gz: 86c3ddb2b9f14393773bde364578287c573fc352c33517cbbd4736b5c0683ba89bb7847aeaaac702d43230f4a1bee4c80fd41837b81bb2f5bb265a53cbf96cca
6
+ metadata.gz: e1ce022f6a242e528c54c818dee4689c49881f32457d0113804327f749dffb91a78b1f55e160e3fb2f750f90b017dd25652af29da59761626a47adfb0a939800
7
+ data.tar.gz: 567f056f47116d4eb68dadff2038041a5c9df017a541ccc0811dbd3be5f250876074aa8b49e7da497656a1de5c138bfbd5e1f6b6d33b2a9fceaf5a3a3f2dbaa3
data/.rubocop.yml CHANGED
@@ -12,7 +12,11 @@ Style/StringLiteralsInInterpolation:
12
12
 
13
13
  Layout/LineLength:
14
14
  Max: 120
15
+ Metrics/MethodLength:
16
+ Max: 20
15
17
 
16
18
  AllCops:
17
19
  NewCops: enable
18
- TargetRubyVersion: 3.0
20
+ TargetRubyVersion: 3.0
21
+ Lint/BinaryOperatorWithIdenticalOperands:
22
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -8,6 +8,7 @@ GEM
8
8
  specs:
9
9
  ast (2.4.2)
10
10
  json (2.6.3)
11
+ json (2.6.3-java)
11
12
  minitest (5.18.0)
12
13
  parallel (1.23.0)
13
14
  parser (3.2.2.1)
@@ -36,6 +37,10 @@ GEM
36
37
  unicode-display_width (2.4.2)
37
38
 
38
39
  PLATFORMS
40
+ universal-java-1.8
41
+ universal-java-11
42
+ x86_64-darwin
43
+ x86_64-darwin-20
39
44
  x86_64-linux
40
45
 
41
46
  DEPENDENCIES
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Debian Version
1
+ # Debian Version (Ruby)
2
2
 
3
3
  A port of "Debian Version" comparison function to Ruby. This is based on
4
4
  [Debian Policy Manual v4.6.20, Section 5.6.12](https://www.debian.org/doc/debian-policy/ch-controlfields.html#version).
@@ -7,22 +7,20 @@ It adapts some of the code from https://github.com/FauxFaux/deb-version and http
7
7
 
8
8
  ## Installation
9
9
 
10
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
11
-
12
10
  Install the gem and add to the application's Gemfile by executing:
13
11
 
14
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
12
+ $ bundle add deb_version
15
13
 
16
14
  If bundler is not being used to manage dependencies, install the gem by executing:
17
15
 
18
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
16
+ $ gem install deb_version
19
17
 
20
18
  ## Usage
21
19
 
22
20
  ```ruby
23
21
  require 'deb_version'
24
- v1 = DebVersion::DebianVersion.new("1.3~rc2")
25
- v2 = DebVersion::DebianVersion.new("1.3")
22
+ v1 = DebVersion.new("1.3~rc2")
23
+ v2 = DebVersion.new("1.3")
26
24
  v1 < v2 # true
27
25
  ```
28
26
 
@@ -32,6 +30,10 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
32
30
 
33
31
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
32
 
33
+ Run `bundle exec rake rubocop` to check for style violations.
34
+
35
+ Run `bundle exec rake test` to run tests.
36
+
35
37
  ## Contributing
36
38
 
37
39
  Bug reports and pull requests are welcome on GitHub at https://github.com/captn3m0/ruby-deb-version. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/captn3m0/ruby-deb-version/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -11,4 +11,4 @@ Minitest::TestTask.create(:test) do |t|
11
11
  t.test_globs = ["test.rb"]
12
12
  end
13
13
 
14
- task :default => :test
14
+ task default: :test
data/deb_version.gemspec CHANGED
@@ -21,15 +21,16 @@ Gem::Specification.new do |spec|
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
22
  spec.files = Dir.chdir(__dir__) do
23
23
  `git ls-files -z`.split("\x0").reject do |f|
24
- (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git all-debian-versions.lst test.rb])
24
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git all-debian-versions.lst
25
+ test.rb])
25
26
  end
26
27
  end
27
-
28
+
28
29
  spec.require_paths = ["lib"]
29
30
 
31
+ spec.add_development_dependency "minitest", "~> 5.18"
30
32
  spec.add_development_dependency "rake", "~> 13.0"
31
33
  spec.add_development_dependency "rubocop", "~> 1.21"
32
- spec.add_development_dependency "minitest", "~> 5.18"
33
34
  spec.add_development_dependency "rubocop-minitest", "~> 0.31.0"
34
35
  spec.add_development_dependency "rubocop-rake", "~> 0.6.0"
35
36
 
@@ -1,86 +1,98 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module DebVersion
4
- class DebianVersion
5
- attr_reader :epoch, :upstream_version, :debian_revision
3
+ # Debian Version comparison class
4
+ # This is based on the Python deb-pkg-tools implementation
5
+ # https://github.com/xolox/python-deb-pkg-tools
6
+ class DebVersion
7
+ attr_reader :epoch, :upstream_version, :debian_revision
6
8
 
7
- include Comparable
9
+ include Comparable
8
10
 
9
- def initialize(version)
10
- @version = version
11
- @epoch = 0
12
- @debian_revision = ""
11
+ def initialize(version)
12
+ @version = version
13
+ @epoch = 0
14
+ @debian_revision = ""
13
15
 
14
- if @version.include? ":"
15
- @epoch, @version = @version.split(":")
16
- @epoch = @epoch.to_i
17
- end
18
-
19
- if @version.include? "-"
20
- @upstream_version, _, @debian_revision = @version.rpartition("-")
21
- else
22
- @upstream_version = @version
23
- end
16
+ if @version.include? ":"
17
+ @epoch, @version = @version.split(":")
18
+ @epoch = @epoch.to_i
24
19
  end
25
20
 
26
- def to_a
27
- [@epoch, @upstream_version, @debian_revision]
21
+ if @version.include? "-"
22
+ @upstream_version, _, @debian_revision = @version.rpartition("-")
23
+ else
24
+ @upstream_version = @version
28
25
  end
26
+ end
29
27
 
30
- def get_digit_prefix(characters)
31
- value = 0
32
- value = (value * 10) + characters.shift.to_i while characters && DebVersion::DIGITS.include?(characters[0])
33
- value
34
- end
28
+ # Convert to an array of [epoch, upstream_version, debian_revision]
29
+ # Helpful for printing and debugging
30
+ def to_a
31
+ [@epoch, @upstream_version, @debian_revision]
32
+ end
35
33
 
36
- def get_non_digit_prefix(characters)
37
- prefix = []
38
- prefix << characters.shift while characters.size.positive? && !DebVersion::DIGITS.include?(characters[0])
39
- prefix
40
- end
34
+ # Internal method to get the largest digit prefix
35
+ def get_digit_prefix(characters)
36
+ value = 0
37
+ value = (value * 10) + characters.shift.to_i while characters && DebVersion::DIGITS.include?(characters[0])
38
+ value
39
+ end
40
+
41
+ # Internal method to get the largest non-digit prefix
42
+ def get_non_digit_prefix(characters)
43
+ prefix = []
44
+ prefix << characters.shift while characters.size.positive? && !DebVersion::DIGITS.include?(characters[0])
45
+ prefix
46
+ end
41
47
 
42
- def compare_strings(version1, version2)
43
- v1 = version1.chars
44
- v2 = version2.chars
45
- while !v1.empty? || !v2.empty?
46
- p1 = get_non_digit_prefix(v1)
47
- p2 = get_non_digit_prefix(v2)
48
- if p1 != p2
49
- loop do
50
- c1 = p1.shift
51
- c2 = p2.shift
52
- break if c1.nil? && c2.nil?
48
+ # Compare strings as per https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
49
+ # Section 5.6.12
50
+ # This is used to compare upstream_version as well as debian_revision
51
+ # rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
52
+ def compare_strings(version1, version2)
53
+ v1 = version1.chars
54
+ v2 = version2.chars
55
+ while !v1.empty? || !v2.empty?
56
+ p1 = get_non_digit_prefix(v1)
57
+ p2 = get_non_digit_prefix(v2)
58
+ if p1 != p2
59
+ loop do
60
+ c1 = p1.shift
61
+ c2 = p2.shift
62
+ break if c1.nil? && c2.nil?
53
63
 
54
- o1 = DebVersion::ORDER_MAPPING.fetch(c1 || "")
55
- o2 = DebVersion::ORDER_MAPPING.fetch(c2 || "")
56
- if o1 < o2
57
- return -1
58
- elsif o1 > o2
59
- return 1
60
- end
64
+ o1 = DebVersion::ORDER_MAPPING.fetch(c1 || "")
65
+ o2 = DebVersion::ORDER_MAPPING.fetch(c2 || "")
66
+ if o1 < o2
67
+ return -1
68
+ elsif o1 > o2
69
+ return 1
61
70
  end
62
71
  end
63
- d1 = get_digit_prefix(v1)
64
- d2 = get_digit_prefix(v2)
65
- if d1 < d2
66
- return -1
67
- elsif d1 > d2
68
- return 1
69
- end
70
72
  end
71
- 0
73
+ d1 = get_digit_prefix(v1)
74
+ d2 = get_digit_prefix(v2)
75
+ if d1 < d2
76
+ return -1
77
+ elsif d1 > d2
78
+ return 1
79
+ end
72
80
  end
81
+ 0
82
+ end
83
+ # rubocop:enable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
73
84
 
74
- def <=>(other)
75
- return epoch <=> other.epoch if epoch != other.epoch
85
+ # Compare two versions
86
+ # using all 3 parts
87
+ def <=>(other)
88
+ return epoch <=> other.epoch if epoch != other.epoch
76
89
 
77
- result = compare_strings(upstream_version, other.upstream_version)
90
+ result = compare_strings(upstream_version, other.upstream_version)
78
91
 
79
- return result if result != 0
92
+ return result if result != 0
80
93
 
81
- return compare_strings(debian_revision, other.debian_revision) if debian_revision || other.debian_revision
94
+ return compare_strings(debian_revision, other.debian_revision) if debian_revision || other.debian_revision
82
95
 
83
- 0
84
- end
96
+ 0
85
97
  end
86
98
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module DebVersion
4
- VERSION = "0.1.0"
3
+ class DebVersion
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/deb_version.rb CHANGED
@@ -3,20 +3,23 @@
3
3
  require_relative "deb_version/version"
4
4
  require_relative "deb_version/compare"
5
5
 
6
- # Main Module for the gem
7
- module DebVersion
6
+ # Constants for the DebVersion class
7
+ class DebVersion
8
8
  class Error < StandardError; end
9
9
  # String of ASCII characters which are considered punctuation characters in the C locale:
10
10
  # Except for ~
11
11
  # Already sorted
12
12
  PUNCTUATION = "!\"\#$%&'()*+,-./:;<=>?@[]^_`{|}".chars
13
+ DIGITS = ("0".."9").to_a
14
+
15
+ # Sorted list of characters used by Debian Version sort.
16
+ # see https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
13
17
  SORT_LIST = ["~", ""] + ("A"..."Z").to_a + ("a"..."z").to_a + PUNCTUATION
14
18
 
15
19
  mapping = {}
16
20
  SORT_LIST.each_with_index do |char, index|
17
21
  mapping[char] = index
18
22
  end
23
+ # Set it to a constant
19
24
  ORDER_MAPPING = mapping
20
-
21
- DIGITS = ("0".."9").to_a
22
25
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deb_version
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nemo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-07 00:00:00.000000000 Z
11
+ date: 2023-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: minitest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '13.0'
19
+ version: '5.18'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '13.0'
26
+ version: '5.18'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rubocop
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.21'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.21'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.18'
47
+ version: '1.21'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.18'
54
+ version: '1.21'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop-minitest
57
57
  requirement: !ruby/object:Gem::Requirement