Class: Dependabot::Nix::VersionedName

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/nix/versioned_name.rb

Overview

Parses a NixOS-style versioned name (e.g. "nixos-26.05", "nixpkgs-24.11-darwin") into prefix, YY.MM version, and suffix, and compares names within a family.

Direct Known Subclasses

Channel

Constant Summary collapse

VERSIONED_NAME_PATTERN =

prefix + YY.MM version + optional suffix, e.g. "nixpkgs-26.05-darwin".

/\A(?<prefix>.+[.\-_])(?<version>\d{2}\.\d{2})(?<suffix>-[a-zA-Z0-9]+)?\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ VersionedName

Returns a new instance of VersionedName.



18
19
20
21
# File 'lib/dependabot/nix/versioned_name.rb', line 18

def initialize(name)
  @name = name
  @match = T.let(VERSIONED_NAME_PATTERN.match(name), T.nilable(MatchData))
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/dependabot/nix/versioned_name.rb', line 24

def name
  @name
end

Instance Method Details

#newer_than?(other) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
# File 'lib/dependabot/nix/versioned_name.rb', line 63

def newer_than?(other)
  this_version = version
  other_version = other.version
  return false unless this_version && other_version

  (this_version <=> other_version) == 1
end

#prefixObject



32
33
34
# File 'lib/dependabot/nix/versioned_name.rb', line 32

def prefix
  @match&.[](:prefix)
end

#same_family?(other) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/dependabot/nix/versioned_name.rb', line 57

def same_family?(other)
  versioned? && other.versioned? &&
    prefix == other.prefix && suffix == other.suffix
end

#suffixObject



37
38
39
# File 'lib/dependabot/nix/versioned_name.rb', line 37

def suffix
  @match&.[](:suffix)
end

#versionObject



48
49
50
51
52
53
# File 'lib/dependabot/nix/versioned_name.rb', line 48

def version
  version_str = version_string
  return unless version_str

  parse_version(version_str)
end

#version_stringObject



42
43
44
# File 'lib/dependabot/nix/versioned_name.rb', line 42

def version_string
  @match&.[](:version)
end

#versioned?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/dependabot/nix/versioned_name.rb', line 27

def versioned?
  !@match.nil?
end