Class: Homebrew::Livecheck::Strategy::ExtractPlist Private

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
livecheck/strategy/extract_plist.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.

The ExtractPlist strategy downloads the file at a URL and extracts versions from contained .plist files.

Defined Under Namespace

Classes: Item

Constant Summary collapse

PRIORITY =

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

A priority of zero causes livecheck to skip the strategy. We only apply Homebrew::Livecheck::Strategy::ExtractPlist using strategy :extract_plist in a livecheck block, as we can’t automatically determine when this can be successfully applied to a URL without fetching the content.

0
URL_MATCH_REGEX =

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

The Regexp used to determine if the strategy applies to the URL.

%r{^https?://}i.freeze

Class Method Summary collapse

Class Method Details

.find_versions(url, regex, cask:, &block) ⇒ Hash{Symbol => T.untyped}

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.

Checks the content at the URL for new versions.

Parameters:

Returns:

Raises:

  • (ArgumentError)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'livecheck/strategy/extract_plist.rb', line 62

def self.find_versions(url, regex, cask:, &block)
  raise ArgumentError, "The #{T.must(name).demodulize} strategy does not support a regex." if regex
  raise ArgumentError, "The #{T.must(name).demodulize} strategy only supports casks." unless T.unsafe(cask)

  match_data = { matches: {}, regex: regex, url: url }

  unversioned_cask_checker = UnversionedCaskChecker.new(cask)
  versions = unversioned_cask_checker.all_versions.transform_values { |v| Item.new(bundle_version: v) }

  if block
    match = block.call(versions)

    unless T.unsafe(match).is_a?(String)
      raise TypeError, "Return value of `strategy :extract_plist` block must be a string."
    end

    match_data[:matches][match] = Version.new(match) if match
  elsif versions.any?
    versions.each_value do |item|
      version = item.bundle_version.nice_version
      match_data[:matches][version] = Version.new(version)
    end
  end

  match_data
end

.match?(url) ⇒ Boolean

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.

Whether the strategy can be applied to the provided URL. The strategy will technically match any HTTP URL but is only usable with a livecheck block containing a regex or block.

Parameters:

Returns:

  • (Boolean)


32
33
34
# File 'livecheck/strategy/extract_plist.rb', line 32

def self.match?(url)
  URL_MATCH_REGEX.match?(url)
end