Class: Homebrew::Livecheck::Strategy::ElectronBuilder Private

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
livecheck/strategy/electron_builder.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 ElectronBuilder strategy fetches content at a URL and parses it as an electron-builder appcast in YAML format.

Constant Summary collapse

NICE_NAME =

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.

"electron-builder"
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 do this for Homebrew::Livecheck::Strategy::ElectronBuilder so we can selectively apply the strategy using strategy :electron_builder in a livecheck block.

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?://.+/.+\.ya?ml$}i.freeze

Class Method Summary collapse

Class Method Details

.find_versions(url, regex, cask: nil, &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:

  • url (String)

    the URL of the content to check

  • regex (Regexp, nil)

    a regex used for matching versions in content

  • cask (Cask::Cask, nil) (defaults to: nil)
  • block (T.proc.params(arg0: Hash).returns(String), nil)

Returns:

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'livecheck/strategy/electron_builder.rb', line 71

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

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

  match_data.merge!(Strategy.page_content(url))
  content = match_data.delete(:content)

  version = version_from_content(content, &block)
  match_data[:matches][version] = Version.new(version) if version

  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.

Parameters:

  • url (String)

    the URL to match against

Returns:

  • (Boolean)


29
30
31
# File 'livecheck/strategy/electron_builder.rb', line 29

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

.version_from_content(content, &block) ⇒ String?

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.

Extract version information from page content.

Parameters:

  • content (String)

    the content to check

  • block (T.proc.params(arg0: Hash).returns(String), nil)

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'livecheck/strategy/electron_builder.rb', line 43

def self.version_from_content(content, &block)
  require "yaml"

  return unless (yaml = YAML.safe_load(content))

  if block
    value = block.call(yaml)
    return value if value.is_a?(String)

    raise TypeError, "Return value of `strategy :electron_builder` block must be a string."
  end

  yaml["version"]
end