Class: Homebrew::Livecheck::LivecheckVersion Private

Inherits:
Object
  • Object
show all
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(package_or_resource, 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(package_or_resource, version)
  versions = case package_or_resource
  when Formula, Resource
    [version]
  when Cask::Cask
    version.to_s.split(",").map { |s| Version.new(s) }
  else
    T.absurd(package_or_resource)
  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