Class: Homebrew::Livecheck::LivecheckVersion Private

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Comparable
Defined in:
livecheck/livecheck_version.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

A formula or cask version, split into its component sub-versions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(versions) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:



31
32
33
# File 'livecheck/livecheck_version.rb', line 31

def initialize(versions)
  @versions = versions
end

Instance Attribute Details

#versionsArray<Version> (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



28
29
30
# File 'livecheck/livecheck_version.rb', line 28

def versions
  @versions
end

Class Method Details

.create(formula_or_cask, version) ⇒ LivecheckVersion

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



15
16
17
18
19
20
21
22
23
24
25
# File 'livecheck/livecheck_version.rb', line 15

def self.create(formula_or_cask, version)
  versions = case formula_or_cask
  when Formula
    [version]
  when Cask::Cask
    version.to_s.split(/[,:]/).map { |s| Version.new(s) }
  else
    T.absurd(formula_or_cask)
  end
  new(versions)
end

Instance Method Details

#<=>(other) ⇒ Integer?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • other (T.untyped)

Returns:

  • (Integer, nil)


36
37
38
39
40
41
42
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 'livecheck/livecheck_version.rb', line 36

def <=>(other)
  return unless other.is_a?(LivecheckVersion)

  lversions = versions
  rversions = other.versions
  max = [lversions.count, rversions.count].max
  l = r = 0

  while l < max
    a = lversions[l] || Version::NULL
    b = rversions[r] || Version::NULL

    if a == b
      l += 1
      r += 1
      next
    elsif !a.null? && b.null?
      return 1 if a > Version::NULL

      l += 1
    elsif a.null? && !b.null?
      return -1 if b > Version::NULL

      r += 1
    else
      return a <=> b
    end
  end

  0
end