Class: Dependabot::Python::Version

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

Constant Summary collapse

VERSION_PATTERN =
'v?([1-9][0-9]*!)?[0-9]+[0-9a-zA-Z]*(?>\.[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/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dependabot/python/version.rb', line 29

def initialize(version)
  @version_string = version.to_s
  version, @local_version = version.split("+")
  version ||= ""
  version = version.gsub(/^v/, "")
  if version.include?("!")
    @epoch, version = version.split("!")
  else
    @epoch = "0"
  end
  version = normalise_prerelease(version)
  version, @post_release_version = version.split(/\.r(?=\d)/)
  version ||= ""
  @local_version = normalise_prerelease(@local_version) if @local_version
  super
end

Instance Attribute Details

#epochObject (readonly)

Returns the value of attribute epoch.



13
14
15
# File 'lib/dependabot/python/version.rb', line 13

def epoch
  @epoch
end

#local_versionObject (readonly)

Returns the value of attribute local_version.



14
15
16
# File 'lib/dependabot/python/version.rb', line 14

def local_version
  @local_version
end

#post_release_versionObject (readonly)

Returns the value of attribute post_release_version.



15
16
17
# File 'lib/dependabot/python/version.rb', line 15

def post_release_version
  @post_release_version
end

Class Method Details

.correct?(version) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/dependabot/python/version.rb', line 23

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

  version.to_s.match?(ANCHORED_VERSION_PATTERN)
end

Instance Method Details

#<=>(other) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dependabot/python/version.rb', line 54

def <=>(other)
  other = Version.new(other.to_s) unless other.is_a?(Python::Version)

  epoch_comparison = epoch_comparison(other)
  return epoch_comparison unless epoch_comparison.zero?

  version_comparison = super(other)
  return version_comparison unless version_comparison.zero?

  post_version_comparison = post_version_comparison(other)
  return post_version_comparison unless post_version_comparison.zero?

  local_version_comparison(other)
end

#inspectObject

:nodoc:



50
51
52
# File 'lib/dependabot/python/version.rb', line 50

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

#to_sObject



46
47
48
# File 'lib/dependabot/python/version.rb', line 46

def to_s
  @version_string
end