vseries 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: e8cfced10322c68ddfac5992311f049865f88eea95532275cda0628656d37e90
4
+ data.tar.gz: 21b33fef686c1208e36ce5be71cf201ba8627dcce93861f7604f63120f4bb329
5
+ SHA512:
6
+ metadata.gz: b612bbc6c810f51542b3280e67ad1c4397c93b1c9c59265d3e8f6087d22c3957265888f0bfceed8df741928df77ad078b33d6705ab2e242923e45f7a97c63a69
7
+ data.tar.gz: 4d51e1dd1449b50d7b629043c6e6b02331b0e5ea71ed56ccc7618495e13daba06c2c7e2336036ce829775931ef6edfffbf10a2e785308bc2279320da6aee63dc
@@ -0,0 +1,20 @@
1
+ name: Ruby
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-16.04
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.4', '2.5', '2.6' ]
11
+ name: Ruby ${{ matrix.ruby }} sample
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ - run: |
18
+ gem install bundler
19
+ bundle install --jobs 4 --retry 3
20
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.5
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in vseries.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vseries (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.1.1)
10
+ diff-lcs (1.3)
11
+ rake (13.0.1)
12
+ rspec (3.9.0)
13
+ rspec-core (~> 3.9.0)
14
+ rspec-expectations (~> 3.9.0)
15
+ rspec-mocks (~> 3.9.0)
16
+ rspec-core (3.9.1)
17
+ rspec-support (~> 3.9.1)
18
+ rspec-expectations (3.9.1)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.9.0)
21
+ rspec-mocks (3.9.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.9.0)
24
+ rspec-support (3.9.2)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 2.0)
31
+ byebug
32
+ rake (~> 13.0)
33
+ rspec (~> 3.0)
34
+ vseries!
35
+
36
+ BUNDLED WITH
37
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Carlos Atkinson
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,60 @@
1
+ # Vseries
2
+
3
+ Vseries is a micro library to work with semantic version tags.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'vseries'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vseries
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+
25
+ require 'vseries'
26
+
27
+ version_1 = Vseries::SemanticVersion.new('1.1.2')
28
+ version_2 = Vseries::SemanticVersion.new('1.1.2-rc.2')
29
+
30
+ version1.to_s # => 1.1.2
31
+
32
+ version_1 == Vseries::SemanticVersion.new('1.1.2') # => true
33
+ version_1 < version_2 # => false
34
+ version_1 <= version_2 # => false
35
+ version_1 > version_2 # => true
36
+ version_1 >= version_2 # => true
37
+
38
+ version_1.up(:patch).to_s # => '1.1.3'
39
+ version_1.up(:minor).to_s # => '1.2.0'
40
+ version_1.up(:major).to_s # => '2.0.0'
41
+
42
+ version_2.up(:patch).to_s # => '1.1.3-rc.1'
43
+ version_2.up(:minor).to_s # => '1.2.0-rc.1'
44
+ version_2.up(:major).to_s # => '2.0.0-rc.1'
45
+
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/catks/vseries.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vseries"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,130 @@
1
+ module Vseries
2
+ class SemanticVersion
3
+ include Comparable
4
+
5
+ REGEXP = /(\d+)\.(\d+)\.(\d+)(-?.*)/
6
+ DEFAULT_PRE_RELEASE_INITIAL_NUMBER = 1
7
+
8
+ class PreRelease
9
+ include Comparable
10
+
11
+ REGEXP = /-?(.+)\.(\d+)/
12
+ BlankPreRelease = Class.new(StandardError)
13
+
14
+ attr_accessor :name, :number
15
+
16
+ def self.with(name:, number: DEFAULT_PRE_RELEASE_INITIAL_NUMBER)
17
+ instance = allocate
18
+ instance.name = name
19
+ instance.number = number
20
+ instance
21
+ end
22
+
23
+ def initialize(pre_release, initial_number: DEFAULT_PRE_RELEASE_INITIAL_NUMBER)
24
+ name, number = pre_release.match(REGEXP)&.captures
25
+
26
+ @initial_number = initial_number
27
+ return if name.nil? && number.nil?
28
+
29
+ @name = name
30
+ @number = number ? number.to_i : initial_number
31
+ end
32
+
33
+ def up
34
+ raise BlankPreRelease if blank?
35
+
36
+ new_pre_release = self.dup
37
+ new_pre_release.number = number ? number + 1 : @initial_number
38
+ new_pre_release
39
+ end
40
+
41
+ def <=>(other)
42
+ return -1 if present? && other.blank?
43
+ return 1 if blank? && other.present?
44
+ to_s <=> other.to_s
45
+ end
46
+
47
+ def blank?
48
+ name.nil? && number.nil?
49
+ end
50
+
51
+ def present?
52
+ !blank?
53
+ end
54
+
55
+ def to_s
56
+ return '' if blank?
57
+
58
+ "-#{@name}.#{@number}"
59
+ end
60
+ end
61
+
62
+ attr_accessor :major, :minor, :patch, :pre_release
63
+
64
+ def initialize(version, pre_release_initial_number: DEFAULT_PRE_RELEASE_INITIAL_NUMBER)
65
+ major, minor, patch, pre_release = version.match(REGEXP).captures
66
+
67
+ @major = major.to_i
68
+ @minor = minor.to_i
69
+ @patch = patch.to_i
70
+ @pre_release = PreRelease.new(pre_release)
71
+
72
+ @pre_release_initial_number = pre_release_initial_number
73
+
74
+ freeze
75
+ end
76
+
77
+ def up(version_type)
78
+ new_version = self.dup
79
+
80
+ case version_type
81
+ when :major
82
+ new_version.major += 1
83
+ new_version.minor = 0
84
+ new_version.patch = 0
85
+ new_version.pre_release.number = @pre_release_initial_number if pre_release?
86
+ when :minor
87
+ new_version.minor += 1
88
+ new_version.patch = 0
89
+ new_version.pre_release.number = @pre_release_initial_number if pre_release?
90
+ when :patch
91
+ new_version.patch += 1
92
+ new_version.pre_release.number = @pre_release_initial_number if pre_release?
93
+ when :pre_release
94
+ new_version.pre_release = new_version.pre_release.up
95
+ end
96
+
97
+ new_version
98
+ end
99
+
100
+ def with_pre_release(name)
101
+ new_version = self.dup
102
+
103
+ return new_version if new_version.pre_release? && new_version.pre_release.name == name
104
+
105
+ new_version.pre_release = PreRelease.with(name: name)
106
+
107
+ new_version
108
+ end
109
+
110
+ def pre_release?
111
+ pre_release.present?
112
+ end
113
+
114
+ def <=>(other)
115
+ return 1 if major > other.major
116
+ return 1 if major == other.major && minor > other.minor
117
+ return 1 if major == other.major && minor == other.minor && patch > other.patch
118
+ return 1 if major == other.major && minor == other.minor && patch == other.patch && pre_release > other.pre_release
119
+ return 0 if major == other.major && minor == other.minor && patch == other.patch && pre_release == other.pre_release
120
+
121
+ -1
122
+ end
123
+
124
+ def to_s
125
+ version = "#{@major}.#{@minor}.#{@patch}"
126
+ version << @pre_release.to_s if @pre_release
127
+ version
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,3 @@
1
+ module Vseries
2
+ VERSION = "0.1.0"
3
+ end
data/lib/vseries.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'vseries/version'
2
+ require 'vseries/semantic_version'
3
+
4
+ module Vseries
5
+ end
data/vseries.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "vseries/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "vseries"
7
+ spec.version = Vseries::VERSION
8
+ spec.authors = ["Carlos Atkinson"]
9
+ spec.email = ["carlos.atks@gmail.com"]
10
+
11
+ spec.summary = %q{Vseries is a small Ruby lib to work with semantic version}
12
+ spec.license = "MIT"
13
+
14
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ #spec.metadata["homepage_uri"] = spec.homepage
17
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
18
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
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(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 13.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "byebug"
33
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vseries
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Atkinson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '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'
69
+ description:
70
+ email:
71
+ - carlos.atks@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".github/workflows/ruby.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/vseries.rb
88
+ - lib/vseries/semantic_version.rb
89
+ - lib/vseries/version.rb
90
+ - vseries.gemspec
91
+ homepage:
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Vseries is a small Ruby lib to work with semantic version
114
+ test_files: []