Class: Dependabot::Python::Version
- Inherits:
-
Version
- Object
- Version
- Dependabot::Python::Version
- 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
-
#epoch ⇒ Object
readonly
Returns the value of attribute epoch.
-
#local_version ⇒ Object
readonly
Returns the value of attribute local_version.
-
#post_release_version ⇒ Object
readonly
Returns the value of attribute post_release_version.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
-
#inspect ⇒ Object
:nodoc:.
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Returns a new instance of Version.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dependabot/python/version.rb', line 30 def initialize(version) @version_string = version.to_s version, @local_version = @version_string.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
#epoch ⇒ Object (readonly)
Returns the value of attribute epoch.
14 15 16 |
# File 'lib/dependabot/python/version.rb', line 14 def epoch @epoch end |
#local_version ⇒ Object (readonly)
Returns the value of attribute local_version.
15 16 17 |
# File 'lib/dependabot/python/version.rb', line 15 def local_version @local_version end |
#post_release_version ⇒ Object (readonly)
Returns the value of attribute post_release_version.
16 17 18 |
# File 'lib/dependabot/python/version.rb', line 16 def post_release_version @post_release_version end |
Class Method Details
.correct?(version) ⇒ Boolean
24 25 26 27 28 |
# File 'lib/dependabot/python/version.rb', line 24 def self.correct?(version) return false if version.nil? version.to_s.match?(ANCHORED_VERSION_PATTERN) end |
Instance Method Details
#<=>(other) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dependabot/python/version.rb', line 55 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 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 |
#inspect ⇒ Object
:nodoc:
51 52 53 |
# File 'lib/dependabot/python/version.rb', line 51 def inspect # :nodoc: "#<#{self.class} #{@version_string}>" end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/dependabot/python/version.rb', line 47 def to_s @version_string end |