Class: Dependabot::Vcpkg::Version

Inherits:
Dependabot::Version
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/vcpkg/version.rb

Constant Summary collapse

VERSION_PATTERN =
/\A([0-9]+(?:\.[0-9]+)*(?:-[0-9A-Za-z\-\.]+)?(?:\+[0-9A-Za-z\-\.]+)?)(?:\#([0-9]+))?\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



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

def initialize(version)
  @version_string = T.let(version.to_s, String)
  parsed_version = parse_version(@version_string)
  super(T.cast(parsed_version[:base_version], String))
  @port_version = T.let(parsed_version[:port_version], T.nilable(Integer))
end

Instance Attribute Details

#port_versionObject (readonly)

Returns the value of attribute port_version.



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

def port_version
  @port_version
end

Instance Method Details

#<=>(other) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dependabot/vcpkg/version.rb', line 33

def <=>(other)
  case other
  when Version
    # Compare with another vcpkg version
    base_comparison = super
    return base_comparison if base_comparison.nil? || !base_comparison.zero?

    # If base versions are equal, compare port versions
    (port_version || 0) <=> (other.port_version || 0)
  when String
    # Compare with a string by creating a version object from it
    begin
      self <=> self.class.new(other)
    rescue ArgumentError
      # If the string isn't a valid version, try comparing as base version only
      super(Gem::Version.new(other))
    end
  when Gem::Version, Dependabot::Version
    # Compare with a regular Gem::Version by comparing just the base version
    super
  end
end

#to_sObject



28
29
30
# File 'lib/dependabot/vcpkg/version.rb', line 28

def to_s
  port_version ? "#{super}##{port_version}" : super
end