Skip to content

Commit

Permalink
Add support for alpha characters in versions
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Jun 9, 2024
1 parent 716f794 commit 58159f5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.1.3] - Unreleased

### Added

- Support for alhpa characters in version numbers
- Support for English names for Greek alphabet letters in version numbers

## [0.1.2] - 2024-06-08

### Fixed:
Expand Down
28 changes: 22 additions & 6 deletions lib/reissue/version_updater.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Reissue
module_function def greeks
%w[alpha beta gamma delta epsilon zeta eta theta kappa lambda mu nu xi omicron pi rho sigma tau upsilon phi chi psi omega]
end

# Provides versioning functionality for the application.
module Versioning
# Provides versioning functionality for the application.
Expand All @@ -9,12 +13,24 @@ module Versioning
# Possible values are :major, :minor, or any other symbol.
# @return [Gem::Version] The updated version.
def redo(segment_name)
if segment_name.to_s == "major"
::Gem::Version.new("#{segments[0].to_i + 1}.0.0")
elsif segment_name.to_s == "minor"
::Gem::Version.new("#{segments[0]}.#{segments[1].to_i + 1}.0")
::Gem::Version.create({
major: [segments[0].next, 0, 0],
minor: [segments[0], segments[1].next, 0],
patch: [segments[0], segments[1], segments[2].next]
}.fetch(segment_name.to_sym).join("."))
end
end

refine ::String do
def greek?
Reissue.greeks.include?(downcase)
end

def next
if greek?
Reissue.greeks[Reissue.greeks.index(downcase).next]
else
::Gem::Version.new("#{segments[0]}.#{segments[1]}.#{segments[2].to_i + 1}")
succ
end
end
end
Expand Down Expand Up @@ -62,7 +78,7 @@ def update(segment)
# Regular expression pattern for matching the version string.
#
# @return [Regexp] The version regex pattern.
def version_regex = /(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/
def version_regex = /(?<major>[a-zA-Z\d]+)\.(?<minor>[a-zA-Z\d]+)\.(?<patch>[a-zA-Z\d]+)/

# Writes the updated version to the specified file.
#
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/alpha_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Reissue
module AlphaGem
VERSION = "0.1.B"
end
end
5 changes: 5 additions & 0 deletions test/fixtures/greek_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Reissue
module GreekGem
VERSION = "2.32.beta"
end
end
14 changes: 14 additions & 0 deletions test/test_version_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,19 @@ class TestVersionUpdater < Minitest::Spec
contents = @version_updater.update("patch")
assert_equal "0.1.1", contents
end

it "works with letters in the version string" do
@file = File.expand_path("fixtures/alpha_version.rb", __dir__)
@version_updater = Reissue::VersionUpdater.new(@file)
contents = @version_updater.update("patch")
assert_equal "0.1.C", contents
end

it "works with greek alphabet names" do
@file = File.expand_path("fixtures/greek_version.rb", __dir__)
@version_updater = Reissue::VersionUpdater.new(@file)
contents = @version_updater.update("patch")
assert_equal "2.32.gamma", contents
end
end
end

0 comments on commit 58159f5

Please sign in to comment.