deb_version 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a0eec3bd476766475cb472300c628c1ef1cf3b34141ef696e75df6a636d99952
4
+ data.tar.gz: ae81bf2ff31ea9e2667a16ca7792346d0cac487ddfe01c998b7f3b08342b4416
5
+ SHA512:
6
+ metadata.gz: 669966c3f74b9dd259e96c6c57b2dc56bdd3ea7785c0e0066ff7699fb62c730e871c9c8ce7b719b4e36060c198cc49363e04f31a99203280d31df9dadaf87458
7
+ data.tar.gz: 86c3ddb2b9f14393773bde364578287c573fc352c33517cbbd4736b5c0683ba89bb7847aeaaac702d43230f4a1bee4c80fd41837b81bb2f5bb265a53cbf96cca
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-rake
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
15
+
16
+ AllCops:
17
+ NewCops: enable
18
+ TargetRubyVersion: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-05-07
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at coc@captnemo.in. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in deb_version.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deb_version (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ json (2.6.3)
11
+ minitest (5.18.0)
12
+ parallel (1.23.0)
13
+ parser (3.2.2.1)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.8.0)
18
+ rexml (3.2.5)
19
+ rubocop (1.50.2)
20
+ json (~> 2.3)
21
+ parallel (~> 1.10)
22
+ parser (>= 3.2.0.0)
23
+ rainbow (>= 2.2.2, < 4.0)
24
+ regexp_parser (>= 1.8, < 3.0)
25
+ rexml (>= 3.2.5, < 4.0)
26
+ rubocop-ast (>= 1.28.0, < 2.0)
27
+ ruby-progressbar (~> 1.7)
28
+ unicode-display_width (>= 2.4.0, < 3.0)
29
+ rubocop-ast (1.28.1)
30
+ parser (>= 3.2.1.0)
31
+ rubocop-minitest (0.31.0)
32
+ rubocop (>= 1.39, < 2.0)
33
+ rubocop-rake (0.6.0)
34
+ rubocop (~> 1.0)
35
+ ruby-progressbar (1.13.0)
36
+ unicode-display_width (2.4.2)
37
+
38
+ PLATFORMS
39
+ x86_64-linux
40
+
41
+ DEPENDENCIES
42
+ deb_version!
43
+ minitest (~> 5.18)
44
+ rake (~> 13.0)
45
+ rubocop (~> 1.21)
46
+ rubocop-minitest (~> 0.31.0)
47
+ rubocop-rake (~> 0.6.0)
48
+
49
+ BUNDLED WITH
50
+ 2.4.12
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Nemo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Debian Version
2
+
3
+ A port of "Debian Version" comparison function to Ruby. This is based on
4
+ [Debian Policy Manual v4.6.20, Section 5.6.12](https://www.debian.org/doc/debian-policy/ch-controlfields.html#version).
5
+
6
+ It adapts some of the code from https://github.com/FauxFaux/deb-version and https://github.com/xolox/python-deb-pkg-tools
7
+
8
+ ## Installation
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
+ Install the gem and add to the application's Gemfile by executing:
13
+
14
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
15
+
16
+ If bundler is not being used to manage dependencies, install the gem by executing:
17
+
18
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require 'deb_version'
24
+ v1 = DebVersion::DebianVersion.new("1.3~rc2")
25
+ v2 = DebVersion::DebianVersion.new("1.3")
26
+ v1 < v2 # true
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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
+
35
+ ## Contributing
36
+
37
+ 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).
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the DebVersion project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/captn3m0/ruby-deb-version/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+ require "minitest/test_task"
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ Minitest::TestTask.create(:test) do |t|
10
+ t.warning = false
11
+ t.test_globs = ["test.rb"]
12
+ end
13
+
14
+ task :default => :test
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/deb_version/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "deb_version"
7
+ spec.version = DebVersion::VERSION
8
+ spec.authors = ["Nemo"]
9
+ spec.email = ["rubygem@captnemo.in"]
10
+
11
+ spec.summary = "A port of Debian Version comparison to Ruby."
12
+ spec.homepage = "https://github.com/captn3m0/ruby-deb-version"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 3.0.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/captn3m0/ruby-deb-version"
18
+ spec.metadata["changelog_uri"] = "https://github.com/captn3m0/ruby-deb-version/blob/main/README.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
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])
25
+ end
26
+ end
27
+
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "rake", "~> 13.0"
31
+ spec.add_development_dependency "rubocop", "~> 1.21"
32
+ spec.add_development_dependency "minitest", "~> 5.18"
33
+ spec.add_development_dependency "rubocop-minitest", "~> 0.31.0"
34
+ spec.add_development_dependency "rubocop-rake", "~> 0.6.0"
35
+
36
+ spec.metadata["rubygems_mfa_required"] = "true"
37
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DebVersion
4
+ class DebianVersion
5
+ attr_reader :epoch, :upstream_version, :debian_revision
6
+
7
+ include Comparable
8
+
9
+ def initialize(version)
10
+ @version = version
11
+ @epoch = 0
12
+ @debian_revision = ""
13
+
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
24
+ end
25
+
26
+ def to_a
27
+ [@epoch, @upstream_version, @debian_revision]
28
+ end
29
+
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
35
+
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
41
+
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?
53
+
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
61
+ end
62
+ 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
+ end
71
+ 0
72
+ end
73
+
74
+ def <=>(other)
75
+ return epoch <=> other.epoch if epoch != other.epoch
76
+
77
+ result = compare_strings(upstream_version, other.upstream_version)
78
+
79
+ return result if result != 0
80
+
81
+ return compare_strings(debian_revision, other.debian_revision) if debian_revision || other.debian_revision
82
+
83
+ 0
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DebVersion
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "deb_version/version"
4
+ require_relative "deb_version/compare"
5
+
6
+ # Main Module for the gem
7
+ module DebVersion
8
+ class Error < StandardError; end
9
+ # String of ASCII characters which are considered punctuation characters in the C locale:
10
+ # Except for ~
11
+ # Already sorted
12
+ PUNCTUATION = "!\"\#$%&'()*+,-./:;<=>?@[]^_`{|}".chars
13
+ SORT_LIST = ["~", ""] + ("A"..."Z").to_a + ("a"..."z").to_a + PUNCTUATION
14
+
15
+ mapping = {}
16
+ SORT_LIST.each_with_index do |char, index|
17
+ mapping[char] = index
18
+ end
19
+ ORDER_MAPPING = mapping
20
+
21
+ DIGITS = ("0".."9").to_a
22
+ end
@@ -0,0 +1,4 @@
1
+ module DebVersion
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deb_version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nemo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.21'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.21'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.18'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.18'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.31.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.31.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.6.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.0
83
+ description:
84
+ email:
85
+ - rubygem@captnemo.in
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".rubocop.yml"
91
+ - CHANGELOG.md
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - deb_version.gemspec
99
+ - lib/deb_version.rb
100
+ - lib/deb_version/compare.rb
101
+ - lib/deb_version/version.rb
102
+ - sig/deb_version.rbs
103
+ homepage: https://github.com/captn3m0/ruby-deb-version
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ homepage_uri: https://github.com/captn3m0/ruby-deb-version
108
+ source_code_uri: https://github.com/captn3m0/ruby-deb-version
109
+ changelog_uri: https://github.com/captn3m0/ruby-deb-version/blob/main/README.md
110
+ rubygems_mfa_required: 'true'
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 3.0.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.3.25
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A port of Debian Version comparison to Ruby.
130
+ test_files: []