Class: Dependabot::Cargo::Version

Inherits:
Gem::Version
  • Object
show all
Defined in:
lib/dependabot/cargo/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]+(\.[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.



18
19
20
21
22
23
# File 'lib/dependabot/cargo/version.rb', line 18

def initialize(version)
  @version_string = version.to_s
  version = version.to_s.split("+").first if version.to_s.include?("+")

  super
end

Class Method Details

.correct?(version) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/dependabot/cargo/version.rb', line 33

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

  version.to_s.match?(ANCHORED_VERSION_PATTERN)
end

Instance Method Details

#inspectObject

:nodoc:



29
30
31
# File 'lib/dependabot/cargo/version.rb', line 29

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

#to_sObject



25
26
27
# File 'lib/dependabot/cargo/version.rb', line 25

def to_s
  @version_string
end