Module: Afterlife::Bump::Semver
- Defined in:
- lib/afterlife/bump/semver.rb
Constant Summary collapse
- DEFAULT_PRERELEASE_NAME =
'rc'
- VERSION_REGEX =
/(\d+\.\d+\.\d+(?:-(?:.+))?)/.freeze
Class Method Summary collapse
-
.calculate_next(part, pre = nil) ⇒ Object
rubocop:disable Metrics/MethodLength.
- .curr_prerelease ⇒ Object
- .parse_prerelease(name) ⇒ Object
- .release ⇒ Object
- .version ⇒ Object
- .version_chunks ⇒ Object
Class Method Details
.calculate_next(part, pre = nil) ⇒ Object
rubocop:disable Metrics/MethodLength
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/afterlife/bump/semver.rb', line 11 def calculate_next(part, pre = nil) # rubocop:disable Metrics/MethodLength x, y, z = release case part.to_sym when :major "#{x + 1}.0.0" when :minor "#{x}.#{y + 1}.0" when :patch "#{x}.#{y}.#{z + 1}" when :pre name, ver = parse_prerelease(pre) "#{x}.#{y}.#{z}-#{name}.#{ver + 1}" end end |
.curr_prerelease ⇒ Object
42 43 44 45 46 47 |
# File 'lib/afterlife/bump/semver.rb', line 42 def curr_prerelease return [DEFAULT_PRERELEASE_NAME, -1] unless version_chunks[1] name, ver = version_chunks[1].split('.') [name, ver.to_i] end |
.parse_prerelease(name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/afterlife/bump/semver.rb', line 26 def parse_prerelease(name) curr_name, curr_ver = curr_prerelease if name # if the user specifies a name different than the current one, reseting the current version curr_ver = -1 if name != curr_name curr_name = name end [curr_name, curr_ver] end |
.release ⇒ Object
38 39 40 |
# File 'lib/afterlife/bump/semver.rb', line 38 def release version_chunks[0].split('.').map(&:to_i) end |
.version ⇒ Object
53 54 55 56 57 |
# File 'lib/afterlife/bump/semver.rb', line 53 def version result = %x(git describe --tags `git rev-list --tags --max-count=1`).chomp # remove the first 'v' if exists, all mifiel tags always have it result[0] == 'v' ? result[1..] : result end |
.version_chunks ⇒ Object
49 50 51 |
# File 'lib/afterlife/bump/semver.rb', line 49 def version_chunks @version_chunks ||= version.split('-') end |