class Puppet::Util::Package::Version::DebianVersion
Constants
- REGEX_DEBIAN_REVISION
alphanumerics and the characters + . ~
- REGEX_EPOCH
Version
string matching regexes- REGEX_FULL
- REGEX_FULL_RX
- REGEX_UPSTREAM_VERSION
alphanumerics and the characters . + - ~ , starts with a digit, ~ only of
debian_revision
is present
Attributes
debian_revision[R]
epoch[R]
upstream_version[R]
Public Class Methods
new(epoch, upstream_version, debian_revision)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 59 def initialize(epoch, upstream_version, debian_revision) 60 @epoch = epoch 61 @upstream_version = upstream_version 62 @debian_revision = debian_revision 63 end
parse(ver)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 17 def self.parse(ver) 18 raise ValidationFailure, "Unable to parse '#{ver}' as a string" unless ver.is_a?(String) 19 20 match, epoch, upstream_version, debian_revision = *ver.match(REGEX_FULL_RX) 21 22 raise ValidationFailure, "Unable to parse '#{ver}' as a debian version identifier" unless match 23 24 new(epoch.to_i, upstream_version, debian_revision).freeze 25 end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 43 def <=>(other) 44 return nil unless other.is_a?(self.class) 45 cmp = @epoch <=> other.epoch 46 if cmp == 0 47 cmp = compare_upstream_version(other) 48 if cmp == 0 49 cmp = compare_debian_revision(other) 50 end 51 end 52 cmp 53 end
eql?(other)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 35 def eql?(other) 36 other.is_a?(self.class) && 37 @epoch.eql?(other.epoch) && 38 @upstream_version.eql?(other.upstream_version) && 39 @debian_revision.eql?(other.debian_revision) 40 end
Also aliased as: ==
to_s()
click to toggle source
# File lib/puppet/util/package/version/debian.rb 27 def to_s 28 s = @upstream_version 29 s = "#{@epoch}:#{s}" if @epoch != 0 30 s = "#{s}-#{@debian_revision}" if @debian_revision 31 s 32 end
Also aliased as: inspect
Private Instance Methods
compare_debian_revision(other)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 71 def compare_debian_revision(other) 72 mine = @debian_revision 73 yours = other.debian_revision 74 compare_debian_versions(mine, yours) 75 end
compare_debian_versions(mine, yours)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 77 def compare_debian_versions(mine, yours) 78 # First the initial part of each string consisting entirely of non-digit characters is determined. 79 # These two parts (one of which may be empty) are compared lexically. If a difference is found it is 80 # returned. The lexical comparison is a comparison of ASCII values modified so that all the letters 81 # sort earlier than all the non-letters and so that a tilde sorts before anything, even the end of a 82 # part. For example, the following parts are in sorted order from earliest to latest: ~~, ~~a, ~, the 83 # empty part, a. 84 # 85 # Then the initial part of the remainder of each string which consists entirely of digit characters 86 # is determined. The numerical values of these two parts are compared, and any difference found is 87 # returned as the result of the comparison. For these purposes an empty string (which can only occur 88 # at the end of one or both version strings being compared) counts as zero. 89 # 90 # These two steps (comparing and removing initial non-digit strings and initial digit strings) are 91 # repeated until a difference is found or both strings are exhausted. 92 93 mine_index = 0 94 yours_index = 0 95 cmp = 0 96 mine ||= '' 97 yours ||= '' 98 while mine_index < mine.length && yours_index < yours.length && cmp == 0 99 #handle ~ 100 _mymatch, mytilde = *match_tildes(mine.slice(mine_index..-1)) 101 mytilde ||= '' 102 103 _yoursmatch, yourstilde = *match_tildes(yours.slice(yours_index..-1)) 104 yourstilde ||= '' 105 106 cmp = -1 * (mytilde.length <=> yourstilde.length) 107 mine_index += mytilde.length 108 yours_index += yourstilde.length 109 110 if cmp == 0 # handle letters 111 112 _mymatch, myletters = *match_letters(mine.slice(mine_index..-1)) 113 myletters ||= '' 114 115 _yoursmatch, yoursletters = *match_letters(yours.slice(yours_index..-1)) 116 yoursletters ||= '' 117 118 cmp = myletters <=> yoursletters 119 mine_index += myletters.length 120 yours_index += yoursletters.length 121 122 if cmp == 0 # handle nonletters except tilde 123 _mymatch, mynon_letters = *match_non_letters(mine.slice(mine_index..-1)) 124 mynon_letters ||= '' 125 126 _yoursmatch, yoursnon_letters = *match_non_letters(yours.slice(yours_index..-1)) 127 yoursnon_letters ||= '' 128 129 cmp = mynon_letters <=> yoursnon_letters 130 mine_index += mynon_letters.length 131 yours_index += yoursnon_letters.length 132 133 if cmp == 0 # handle digits 134 _mymatch, mydigits = *match_digits(mine.slice(mine_index..-1)) 135 mydigits ||= '' 136 137 _yoursmatch, yoursdigits = *match_digits(yours.slice(yours_index..-1)) 138 yoursdigits ||= '' 139 140 cmp = mydigits.to_i <=> yoursdigits.to_i 141 mine_index += mydigits.length 142 yours_index += yoursdigits.length 143 end 144 end 145 end 146 end 147 if cmp == 0 148 if mine_index < mine.length && match_tildes(mine[mine_index]) 149 cmp = -1 150 elsif yours_index < yours.length && match_tildes(yours[yours_index]) 151 cmp = 1 152 else 153 cmp = mine.length <=> yours.length 154 end 155 end 156 cmp 157 end
compare_upstream_version(other)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 65 def compare_upstream_version(other) 66 mine = @upstream_version 67 yours = other.upstream_version 68 compare_debian_versions(mine, yours) 69 end
match_digits(a)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 159 def match_digits(a) 160 a.match(/^([0-9]+)/) 161 end
match_letters(a)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 171 def match_letters(a) 172 a.match(/^([A-Za-z]+)/) 173 end
match_non_letters(a)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 163 def match_non_letters(a) 164 a.match(/^([\.\+-]+)/) 165 end
match_tildes(a)
click to toggle source
# File lib/puppet/util/package/version/debian.rb 167 def match_tildes(a) 168 a.match(/^(~+)/) 169 end