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