Module: Beaker::Shared::Semvar
- Included in:
- Beaker::Shared
- Defined in:
- lib/beaker/shared/semvar.rb
Instance Method Summary collapse
-
#max_version(versions, default = nil) ⇒ String?
Gets the max semver version from a list of them.
-
#version_is_less(a, b) ⇒ Boolean
Is semver-ish version a less than semver-ish version b.
Instance Method Details
#max_version(versions, default = nil) ⇒ String?
Note:
nil values will be skipped
Note:
versions parameter will be copied so that the original won’t be tampered with
Gets the max semver version from a list of them
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/beaker/shared/semvar.rb', line 49 def max_version(versions, default=nil) return default if !versions || versions.empty? versions_copy = versions.dup highest = versions_copy.shift versions_copy.each do |version| next if !version highest = version if version_is_less(highest, version) end highest end |
#version_is_less(a, b) ⇒ Boolean
Note:
3.0.0-160-gac44cfb is greater than 3.0.0, and 2.8.2
Note:
-rc being less than final builds is not yet implemented.
Is semver-ish version a less than semver-ish version b
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/beaker/shared/semvar.rb', line 12 def version_is_less a, b a_nums = a.split('-')[0].split('.') b_nums = b.split('-')[0].split('.') (0...a_nums.length).each do |i| if i < b_nums.length if a_nums[i].to_i < b_nums[i].to_i return true elsif a_nums[i].to_i > b_nums[i].to_i return false end else return false end end #checks all dots, they are equal so examine the rest a_rest = a.split('-', 2)[1] b_rest = b.split('-', 2)[1] if a_rest and b_rest and a_rest < b_rest return false elsif a_rest and not b_rest return false elsif not a_rest and b_rest return true end return false end |