Class: Dependabot::GoModules::Version

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

Constant Summary collapse

VERSION_PATTERN =
'[0-9]+[0-9a-zA-Z]*(?>\.[0-9a-zA-Z]+)*' \
'(-[0-9A-Za-z-]+(\.[0-9a-zA-Z-]+)*)?' \
'(\+incompatible)?'
ANCHORED_VERSION_PATTERN =
/\A\s*(#{VERSION_PATTERN})?\s*\z/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dependabot/go_modules/version.rb', line 33

def initialize(version)
  @version_string = T.let(version.to_s.gsub(/^v/, ""), String)
  version = version.gsub(/^v/, "") if version.is_a?(String)
  version = version.to_s.split("+").first if version.to_s.include?("+")
  # NOTE: avoid the name `@prerelease`; RubyGems 4's Gem::Version#prerelease?
  # memoizes its boolean result into an `@prerelease` ivar, so reusing that
  # name here would corrupt the inherited prerelease? check.
  @prerelease_suffix = T.let(nil, T.nilable(String))
  version, @prerelease_suffix = version.to_s.split("-", 2) if version.to_s.include?("-")

  super
end

Class Method Details

.correct?(version) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/dependabot/go_modules/version.rb', line 25

def self.correct?(version)
  version = version.gsub(/^v/, "") if version.is_a?(String)
  version = version.to_s.split("+").first if version.to_s.include?("+")

  super
end

Instance Method Details

#<=>(other) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/dependabot/go_modules/version.rb', line 70

def <=>(other)
  result = super
  return if result.nil?
  return result unless result.zero?

  other = self.class.new(other.to_s) unless other.is_a?(Version)
  compare_prerelease(@prerelease_suffix || "", T.unsafe(other).prerelease_suffix || "")
end

#inspectObject

:nodoc:



47
48
49
# File 'lib/dependabot/go_modules/version.rb', line 47

def inspect # :nodoc:
  "#<#{self.class} #{@version_string.inspect}>"
end

#prerelease?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
# File 'lib/dependabot/go_modules/version.rb', line 62

def prerelease?
  suffix = @prerelease_suffix
  return true if suffix && !suffix.empty?

  super
end

#to_sObject



52
53
54
# File 'lib/dependabot/go_modules/version.rb', line 52

def to_s
  @version_string
end