Class: Dependabot::Utils::Python::Version
- Inherits:
-
Gem::Version
- Object
- Gem::Version
- Dependabot::Utils::Python::Version
- Defined in:
- lib/dependabot/utils/python/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]+(\.[0-9a-zA-Z]+)*)?'
- ANCHORED_VERSION_PATTERN =
/\A\s*(#{VERSION_PATTERN})?\s*\z/.freeze
Instance Attribute Summary collapse
-
#local_version ⇒ Object
readonly
Returns the value of attribute local_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.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dependabot/utils/python/version.rb', line 24 def initialize(version) @version_string = version.to_s version, @local_version = version.split("+") version ||= "" version = normalise_prerelease(version) if @local_version @local_version = normalise_prerelease(@local_version) end super end |
Instance Attribute Details
#local_version ⇒ Object (readonly)
Returns the value of attribute local_version.
11 12 13 |
# File 'lib/dependabot/utils/python/version.rb', line 11 def local_version @local_version end |
Class Method Details
.correct?(version) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/dependabot/utils/python/version.rb', line 18 def self.correct?(version) return false if version.nil? version.to_s.match?(ANCHORED_VERSION_PATTERN) end |
Instance Method Details
#<=>(other) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dependabot/utils/python/version.rb', line 43 def <=>(other) version_comparison = super(other) return version_comparison unless version_comparison.zero? unless other.is_a?(Utils::Python::Version) return local_version.nil? ? 0 : 1 end # Local version comparison works differently in Python: `1.0.beta` # compares as greater than `1.0`. To accommodate, we make the # strings the same length before comparing. lhsegments = local_version.to_s.split(".").map(&:downcase) rhsegments = other.local_version.to_s.split(".").map(&:downcase) limit = [lhsegments.count, rhsegments.count].min lhs = ["1", *lhsegments.first(limit)].join(".") rhs = ["1", *rhsegments.first(limit)].join(".") local_comparison = Gem::Version.new(lhs) <=> Gem::Version.new(rhs) return local_comparison unless local_comparison.zero? lhsegments.count <=> rhsegments.count end |
#inspect ⇒ Object
:nodoc:
39 40 41 |
# File 'lib/dependabot/utils/python/version.rb', line 39 def inspect # :nodoc: "#<#{self.class} #{@version_string}>" end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/dependabot/utils/python/version.rb', line 35 def to_s @version_string end |