Module: Kettle::Dev::Versioning
- Defined in:
- lib/kettle/dev/versioning.rb
Overview
Shared helpers for version detection and bump classification.
Class Method Summary collapse
-
.abort!(msg) ⇒ void
Abort via ExitAdapter if available; otherwise Kernel.abort.
-
.classify_bump(prev, cur) ⇒ Symbol
Classify the bump type from prev -> cur.
-
.detect_version(root) ⇒ String
Detects a unique VERSION constant declared under lib/**/version.rb.
-
.epic_major?(major) ⇒ Boolean
Whether MAJOR is an EPIC version (strictly > 1000).
Class Method Details
.abort!(msg) ⇒ void
This method returns an undefined value.
Abort via ExitAdapter if available; otherwise Kernel.abort
63 64 65 |
# File 'lib/kettle/dev/versioning.rb', line 63 def abort!(msg) Kettle::Dev::ExitAdapter.abort(msg) end |
.classify_bump(prev, cur) ⇒ Symbol
Classify the bump type from prev -> cur.
EPIC is a MAJOR > 1000.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kettle/dev/versioning.rb', line 31 def classify_bump(prev, cur) pv = Gem::Version.new(prev) cv = Gem::Version.new(cur) return :same if cv == pv return :downgrade if cv < pv pmaj, pmin, ppatch = (pv.segments + [0, 0, 0])[0, 3] cmaj, cmin, cpatch = (cv.segments + [0, 0, 0])[0, 3] if cmaj > pmaj return :epic if cmaj && cmaj > 1000 :major elsif cmin > pmin :minor elsif cpatch > ppatch :patch else # Fallback; should be covered by :same above, but in case of weird segment shapes :same end end |
.detect_version(root) ⇒ String
Detects a unique VERSION constant declared under lib/**/version.rb
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kettle/dev/versioning.rb', line 12 def detect_version(root) candidates = Dir[File.join(root, "lib", "**", "version.rb")] abort!("Could not find version.rb under lib/**.") if candidates.empty? versions = candidates.map do |path| content = File.read(path) m = content.match(/VERSION\s*=\s*(["'])([^"']+)\1/) next unless m m[2] end.compact abort!("VERSION constant not found in #{root}/lib/**/version.rb") if versions.none? abort!("Multiple VERSION constants found to be out of sync (#{versions.inspect}) in #{root}/lib/**/version.rb") unless versions.uniq.length == 1 versions.first end |
.epic_major?(major) ⇒ Boolean
Whether MAJOR is an EPIC version (strictly > 1000)
56 57 58 |
# File 'lib/kettle/dev/versioning.rb', line 56 def epic_major?(major) major && major > 1000 end |