Class: Dependabot::Nuget::Version
- Inherits:
-
Gem::Version
- Object
- Gem::Version
- Dependabot::Nuget::Version
- Defined in:
- lib/dependabot/nuget/version.rb
Constant Summary collapse
- VERSION_PATTERN =
Gem::Version::VERSION_PATTERN + '(\+[0-9a-zA-Z\-.]+)?'
- ANCHORED_VERSION_PATTERN =
/\A\s*(#{VERSION_PATTERN})?\s*\z/.freeze
Instance Attribute Summary collapse
-
#build_info ⇒ Object
readonly
Returns the value of attribute build_info.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#compare_build_info(other) ⇒ Object
rubocop:enable Metrics/PerceivedComplexity.
-
#compare_prerelease_part(other) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
- #compare_release(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 |
# File 'lib/dependabot/nuget/version.rb', line 24 def initialize(version) @version_string = version.to_s if version.to_s.include?("+") version, @build_info = version.to_s.split("+") end super end |
Instance Attribute Details
#build_info ⇒ Object (readonly)
Returns the value of attribute build_info.
13 14 15 |
# File 'lib/dependabot/nuget/version.rb', line 13 def build_info @build_info end |
Class Method Details
.correct?(version) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/dependabot/nuget/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
42 43 44 45 46 47 48 49 50 |
# File 'lib/dependabot/nuget/version.rb', line 42 def <=>(other) version_comparison = compare_release(other) return version_comparison unless version_comparison.zero? version_comparison = compare_prerelease_part(other) return version_comparison unless version_comparison.zero? compare_build_info(other) end |
#compare_build_info(other) ⇒ Object
rubocop:enable Metrics/PerceivedComplexity
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/dependabot/nuget/version.rb', line 85 def compare_build_info(other) return build_info.nil? ? 0 : 1 unless other.is_a?(Nuget::Version) # Build information comparison lhsegments = build_info.to_s.split(".").map(&:downcase) rhsegments = other.build_info.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 |
#compare_prerelease_part(other) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dependabot/nuget/version.rb', line 60 def compare_prerelease_part(other) release_str = @version_string.split("-").first&.split("+")&.first || "" prerelease_string = @version_string. sub(release_str, ""). sub("-", ""). split("+"). first prerelease_string = nil if prerelease_string == "" other_release_str = other.to_s.split("-").first&.split("+")&.first || "" other_prerelease_string = other.to_s. sub(other_release_str, ""). sub("-", ""). split("+"). first other_prerelease_string = nil if other_prerelease_string == "" return -1 if prerelease_string && !other_prerelease_string return 1 if !prerelease_string && other_prerelease_string prerelease_string.<=>(other_prerelease_string) end |
#compare_release(other) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/dependabot/nuget/version.rb', line 52 def compare_release(other) release_str = @version_string.split("-").first&.split("+")&.first || "" other_release_str = other.to_s.split("-").first&.split("+")&.first || "" Gem::Version.new(release_str).<=>(Gem::Version.new(other_release_str)) end |
#inspect ⇒ Object
:nodoc:
38 39 40 |
# File 'lib/dependabot/nuget/version.rb', line 38 def inspect # :nodoc: "#<#{self.class} #{@version_string}>" end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/dependabot/nuget/version.rb', line 34 def to_s @version_string end |