Class: Dependabot::Gradle::Version

Inherits:
Gem::Version
  • Object
show all
Defined in:
lib/dependabot/gradle/version.rb

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



40
41
42
43
# File 'lib/dependabot/gradle/version.rb', line 40

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

Class Method Details

.correct?(version) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/dependabot/gradle/version.rb', line 34

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

  version.to_s.match?(ANCHORED_VERSION_PATTERN)
end

Instance Method Details

#<=>(other) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dependabot/gradle/version.rb', line 58

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: prefixed_tokens[index][0],
      token: prefixed_tokens[index][1..-1] || "",
      other_prefix: other_prefixed_tokens[index][0],
      other_token: other_prefixed_tokens[index][1..-1] || ""
    )
    return comp unless comp.zero?
  end

  0
end

#prerelease?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
# File 'lib/dependabot/gradle/version.rb', line 49

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

    NAMED_QUALIFIERS_HIERARCHY[token] < 6
  end
end

#to_sObject



45
46
47
# File 'lib/dependabot/gradle/version.rb', line 45

def to_s
  @version_string
end