forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.rb
77 lines (60 loc) · 2.15 KB
/
version.rb
1
2
3
4
5
6
7
8
9
10
11
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# typed: strong
# frozen_string_literal: true
require "sorbet-runtime"
module Dependabot
class Version < Gem::Version
extend T::Sig
extend T::Helpers
abstract!
VersionParameter = T.type_alias { T.nilable(T.any(String, Integer, Gem::Version)) }
sig { override.overridable.params(version: VersionParameter).void }
def initialize(version)
@original_version = T.let(version.to_s, String)
super
end
sig { override.overridable.params(version: VersionParameter).returns(Dependabot::Version) }
def self.new(version)
T.cast(super, Dependabot::Version)
end
# Opt-in to Rubygems 4 behavior
sig { override.overridable.params(version: VersionParameter).returns(T::Boolean) }
def self.correct?(version)
return false if version.nil?
version.to_s.match?(ANCHORED_VERSION_PATTERN)
end
sig { overridable.returns(String) }
def to_semver
@original_version
end
sig { overridable.returns(T::Array[String]) }
def ignored_patch_versions
parts = to_semver.split(".")
version_parts = parts.fill("0", parts.length...2)
upper_parts = version_parts.first(1) + [version_parts[1].to_i + 1]
lower_bound = "> #{to_semver}"
upper_bound = "< #{upper_parts.join('.')}"
["#{lower_bound}, #{upper_bound}"]
end
sig { overridable.returns(T::Array[String]) }
def ignored_minor_versions
parts = to_semver.split(".")
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]
lower_bound = ">= #{lower_parts.join('.')}"
upper_bound = "< #{upper_parts.join('.')}"
["#{lower_bound}, #{upper_bound}"]
end
sig { overridable.returns(T::Array[String]) }
def ignored_major_versions
version_parts = to_semver.split(".")
lower_parts = [version_parts[0].to_i + 1] + [lowest_prerelease_suffix]
lower_bound = ">= #{lower_parts.join('.')}"
[lower_bound]
end
sig { returns(String) }
def lowest_prerelease_suffix
"a"
end
end
end