Class: Dependabot::Uv::Version
- Inherits:
-
Version
- Object
- Version
- Dependabot::Uv::Version
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/uv/version.rb
Constant Summary collapse
- INFINITY =
T.let(1000, Integer)
- NEGATIVE_INFINITY =
T.let(-INFINITY, Integer)
- VERSION_PATTERN =
/ v? (?: (?:(?<epoch>[0-9]+)!)? # epoch (?<release>[0-9]+(?:\.[0-9]+)*) # release (?<pre> # prerelease [-_\.]? (?<pre_l>(a|b|c|rc|alpha|beta|pre|preview)) [-_\.]? (?<pre_n>[0-9]+)? )? (?<post> # post release (?:-(?<post_n1>[0-9]+)) | (?: [-_\.]? (?<post_l>post|rev|r) [-_\.]? (?<post_n2>[0-9]+)? ) )? (?<dev> # dev release [-_\.]? (?<dev_l>dev) [-_\.]? (?<dev_n>[0-9]+)? )? ) (?:\+(?<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version /ix- ANCHORED_VERSION_PATTERN =
/\A\s*#{VERSION_PATTERN}\s*\z/
Instance Attribute Summary collapse
-
#dev ⇒ Object
readonly
Returns the value of attribute dev.
-
#epoch ⇒ Object
readonly
Returns the value of attribute epoch.
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#post ⇒ Object
readonly
Returns the value of attribute post.
-
#pre ⇒ Object
readonly
Returns the value of attribute pre.
-
#release_segment ⇒ Object
readonly
Returns the value of attribute release_segment.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #compare_keys(key, other_key) ⇒ Object
- #dev_cmp_key ⇒ Object
- #ignored_major_versions ⇒ Object
- #ignored_minor_versions ⇒ Object
- #ignored_patch_versions ⇒ Object
-
#initialize(version) ⇒ Version
constructor
rubocop:disable Metrics/AbcSize.
-
#inspect ⇒ Object
:nodoc:.
- #local_cmp_key ⇒ Object
- #lowest_prerelease_suffix ⇒ Object
- #post_cmp_key ⇒ Object
- #pre_cmp_key ⇒ Object
- #prerelease? ⇒ Boolean
- #release ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
rubocop:disable Metrics/AbcSize
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/dependabot/uv/version.rb', line 79 def initialize(version) # rubocop:disable Metrics/AbcSize raise Dependabot::BadRequirementError, "Malformed version string - string is nil" if version.nil? @version_string = T.let(version.to_s, String) raise Dependabot::BadRequirementError, "Malformed version string - string is empty" if @version_string.empty? matches = ANCHORED_VERSION_PATTERN.match(@version_string.downcase) unless matches raise Dependabot::BadRequirementError, "Malformed version string - #{@version_string} does not match regex" end @epoch = T.let(matches["epoch"].to_i, Integer) @release_segment = T.let(matches["release"]&.split(".")&.map(&:to_i) || [], T::Array[Integer]) @pre = T.let( parse_letter_version(matches["pre_l"], matches["pre_n"]), T.nilable(T::Array[T.any(String, Integer)]) ) @post = T.let( parse_letter_version(matches["post_l"], matches["post_n1"] || matches["post_n2"]), T.nilable(T::Array[T.any(String, Integer)]) ) @dev = T.let( parse_letter_version(matches["dev_l"], matches["dev_n"]), T.nilable(T::Array[T.any(String, Integer)]) ) @local = T.let(parse_local_version(matches["local"]), T.nilable(T::Array[T.any(String, Integer)])) super(matches["release"] || "") end |
Instance Attribute Details
#dev ⇒ Object (readonly)
Returns the value of attribute dev.
23 24 25 |
# File 'lib/dependabot/uv/version.rb', line 23 def dev @dev end |
#epoch ⇒ Object (readonly)
Returns the value of attribute epoch.
17 18 19 |
# File 'lib/dependabot/uv/version.rb', line 17 def epoch @epoch end |
#local ⇒ Object (readonly)
Returns the value of attribute local.
32 33 34 |
# File 'lib/dependabot/uv/version.rb', line 32 def local @local end |
#post ⇒ Object (readonly)
Returns the value of attribute post.
29 30 31 |
# File 'lib/dependabot/uv/version.rb', line 29 def post @post end |
#pre ⇒ Object (readonly)
Returns the value of attribute pre.
26 27 28 |
# File 'lib/dependabot/uv/version.rb', line 26 def pre @pre end |
#release_segment ⇒ Object (readonly)
Returns the value of attribute release_segment.
20 21 22 |
# File 'lib/dependabot/uv/version.rb', line 20 def release_segment @release_segment end |
Class Method Details
.correct?(version) ⇒ Boolean
72 73 74 75 76 |
# File 'lib/dependabot/uv/version.rb', line 72 def self.correct?(version) return false if version.nil? version.to_s.match?(ANCHORED_VERSION_PATTERN) end |
.new(version) ⇒ Object
112 113 114 |
# File 'lib/dependabot/uv/version.rb', line 112 def self.new(version) T.cast(super, Dependabot::Uv::Version) end |
Instance Method Details
#<=>(other) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/dependabot/uv/version.rb', line 137 def <=>(other) other = Dependabot::Uv::Version.new(other.to_s) unless other.is_a?(Dependabot::Uv::Version) epoch_comparison = epoch <=> other.epoch return epoch_comparison unless epoch_comparison.zero? release_comparison = release_version_comparison(other) return release_comparison unless release_comparison.zero? pre_comparison = compare_keys(pre_cmp_key, other.pre_cmp_key) return pre_comparison unless pre_comparison.zero? post_comparison = compare_keys(post_cmp_key, other.post_cmp_key) return post_comparison unless post_comparison.zero? dev_comparison = compare_keys(dev_cmp_key, other.dev_cmp_key) return dev_comparison unless dev_comparison.zero? compare_keys(local_cmp_key, other.local_cmp_key) end |
#compare_keys(key, other_key) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/dependabot/uv/version.rb', line 164 def compare_keys(key, other_key) if key.is_a?(Integer) && other_key.is_a?(Integer) key <=> other_key elsif key.is_a?(Array) && other_key.is_a?(Array) key <=> other_key elsif key.is_a?(Integer) key == NEGATIVE_INFINITY ? -1 : 1 elsif other_key.is_a?(Integer) other_key == NEGATIVE_INFINITY ? 1 : -1 end end |
#dev_cmp_key ⇒ Object
217 218 219 220 221 222 |
# File 'lib/dependabot/uv/version.rb', line 217 def dev_cmp_key # Versions without a dev segment should sort after those with one. return INFINITY if dev.nil? T.must(dev) end |
#ignored_major_versions ⇒ Object
253 254 255 256 257 258 259 |
# File 'lib/dependabot/uv/version.rb', line 253 def ignored_major_versions version_parts = release_segment # e.g [1,2,3] if version is 1.2.3-alpha3 lower_parts = [version_parts[0].to_i + 1] + [lowest_prerelease_suffix] # earliest next major version prerelease lower_bound = ">= #{lower_parts.join('.')}" [lower_bound] end |
#ignored_minor_versions ⇒ Object
241 242 243 244 245 246 247 248 249 250 |
# File 'lib/dependabot/uv/version.rb', line 241 def ignored_minor_versions parts = release_segment # e.g [1,2,3] if version is 1.2.3-alpha3 version_parts = parts.fill(0, parts.length...2) lower_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + [lowest_prerelease_suffix] upper_parts = version_parts.first(0) + [version_parts[0].to_i + 1] + [lowest_prerelease_suffix] lower_bound = ">= #{lower_parts.join('.')}" upper_bound = "< #{upper_parts.join('.')}" ["#{lower_bound}, #{upper_bound}"] end |
#ignored_patch_versions ⇒ Object
230 231 232 233 234 235 236 237 238 |
# File 'lib/dependabot/uv/version.rb', line 230 def ignored_patch_versions parts = release_segment # e.g [1,2,3] if version is 1.2.3-alpha3 version_parts = parts.fill(0, parts.length...2) upper_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + [lowest_prerelease_suffix] lower_bound = "> #{self}" upper_bound = "< #{upper_parts.join('.')}" ["#{lower_bound}, #{upper_bound}"] end |
#inspect ⇒ Object
:nodoc:
122 123 124 |
# File 'lib/dependabot/uv/version.rb', line 122 def inspect # :nodoc: "#<#{self.class} #{@version_string}>" end |
#local_cmp_key ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/dependabot/uv/version.rb', line 188 def local_cmp_key if local.nil? # Versions without a local segment should sort before those with one. NEGATIVE_INFINITY else # According to PEP440. # - Alphanumeric segments sort before numeric segments # - Alphanumeric segments sort lexicographically # - Numeric segments sort numerically # - Shorter versions sort before longer versions when the prefixes match exactly T.must(local).map do |token| if token.is_a?(Integer) [token, ""] else [NEGATIVE_INFINITY, token] end end.flatten end end |
#lowest_prerelease_suffix ⇒ Object
225 226 227 |
# File 'lib/dependabot/uv/version.rb', line 225 def lowest_prerelease_suffix "dev0" end |
#post_cmp_key ⇒ Object
209 210 211 212 213 214 |
# File 'lib/dependabot/uv/version.rb', line 209 def post_cmp_key # Versions without a post segment should sort before those with one. return NEGATIVE_INFINITY if post.nil? T.must(post) end |
#pre_cmp_key ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/dependabot/uv/version.rb', line 177 def pre_cmp_key if pre.nil? && post.nil? && dev # sort 1.0.dev0 before 1.0a0 NEGATIVE_INFINITY elsif pre.nil? INFINITY # versions without a pre-release should sort after those with one. else T.must(pre) end end |
#prerelease? ⇒ Boolean
127 128 129 |
# File 'lib/dependabot/uv/version.rb', line 127 def prerelease? !!(pre || dev) end |
#release ⇒ Object
132 133 134 |
# File 'lib/dependabot/uv/version.rb', line 132 def release Dependabot::Uv::Version.new(release_segment.join(".")) end |
#to_s ⇒ Object
117 118 119 |
# File 'lib/dependabot/uv/version.rb', line 117 def to_s @version_string end |