Class: Dependabot::Gradle::Version

Inherits:
Version
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/gradle/version.rb

Constant Summary collapse

NULL_VALUES =
T.let(%w(0 final ga).freeze, T::Array[String])
PREFIXED_TOKEN_HIERARCHY =
T.let(
  {
    "." => { qualifier: 1, number: 4 },
    "-" => { qualifier: 2, number: 3 },
    "_" => { qualifier: 2, number: 3 }
  }.freeze,
  T::Hash[String, T::Hash[Symbol, Integer]]
)
NAMED_QUALIFIERS_HIERARCHY =
T.let(
  {
    "a" => 1, "alpha" => 1,
    "b" => 2, "beta"      => 2,
    "m" => 3, "milestone" => 3,
    "rc" => 4, "cr" => 4, "pr" => 4, "pre" => 4,
    "snapshot" => 5, "dev" => 5,
    "ga" => 6, "" => 6, "final" => 6,
    "sp" => 7
  }.freeze,
  T::Hash[String, Integer]
)
VERSION_PATTERN =
T.let(
  "[0-9a-zA-Z]+" \
  '(?>\.[0-9a-zA-Z]*)*' \
  '([_\-\+][0-9A-Za-z_-]*(\.[0-9A-Za-z_-]*)*)?',
  String
)
ANCHORED_VERSION_PATTERN =
T.let(/\A\s*(#{VERSION_PATTERN})?\s*\z/, Regexp)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



55
56
57
58
# File 'lib/dependabot/gradle/version.rb', line 55

def initialize(version)
  @version_string = T.let(version.to_s, String)
  super(version.to_s.tr("_", "-"))
end

Class Method Details

.correct?(version) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/dependabot/gradle/version.rb', line 48

def self.correct?(version)
  return false if version.nil?

  version.to_s.match?(ANCHORED_VERSION_PATTERN)
end

Instance Method Details

#<=>(other) ⇒ Object



76
77
78
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
# File 'lib/dependabot/gradle/version.rb', line 76

def <=>(other)
  version = stringify_version(@version_string)
  version = fill_tokens(version)
  version = trim_version(version)

  other_version = stringify_version(other)
  other_version = fill_tokens(other_version)
  other_version = trim_version(other_version)

  version, other_version = convert_dates(version, other_version)

  prefixed_tokens = split_into_prefixed_tokens(version)
  other_prefixed_tokens = split_into_prefixed_tokens(other_version)

  prefixed_tokens, other_prefixed_tokens =
    pad_for_comparison(prefixed_tokens, other_prefixed_tokens)

  prefixed_tokens.count.times.each do |index|
    comp = compare_prefixed_token(
      prefix: T.must(T.must(prefixed_tokens[index])[0]),
      token: T.must(prefixed_tokens[index])[1..-1] || "",
      other_prefix: T.must(T.must(other_prefixed_tokens[index])[0]),
      other_token: T.must(other_prefixed_tokens[index])[1..-1] || ""
    )
    return comp unless comp.zero?
  end

  0
end

#prerelease?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
# File 'lib/dependabot/gradle/version.rb', line 66

def prerelease?
  tokens.any? do |token|
    next true if token == "eap"
    next false unless NAMED_QUALIFIERS_HIERARCHY[token]

    T.must(NAMED_QUALIFIERS_HIERARCHY[token]) < 6
  end
end

#to_sObject



61
62
63
# File 'lib/dependabot/gradle/version.rb', line 61

def to_s
  @version_string
end