Module: Homebrew::Livecheck::Strategy Private
- Extended by:
- T::Sig
- Defined in:
- brew/Library/Homebrew/livecheck/strategy.rb,
brew/Library/Homebrew/livecheck/strategy/git.rb,
brew/Library/Homebrew/livecheck/strategy/gnu.rb,
brew/Library/Homebrew/livecheck/strategy/npm.rb,
brew/Library/Homebrew/livecheck/strategy/cpan.rb,
brew/Library/Homebrew/livecheck/strategy/pypi.rb,
brew/Library/Homebrew/livecheck/strategy/xorg.rb,
brew/Library/Homebrew/livecheck/strategy/gnome.rb,
brew/Library/Homebrew/livecheck/strategy/apache.rb,
brew/Library/Homebrew/livecheck/strategy/hackage.rb,
brew/Library/Homebrew/livecheck/strategy/sparkle.rb,
brew/Library/Homebrew/livecheck/strategy/bitbucket.rb,
brew/Library/Homebrew/livecheck/strategy/launchpad.rb,
brew/Library/Homebrew/livecheck/strategy/page_match.rb,
brew/Library/Homebrew/livecheck/strategy/sourceforge.rb,
brew/Library/Homebrew/livecheck/strategy/header_match.rb,
brew/Library/Homebrew/livecheck/strategy/github_latest.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
The Livecheck::Strategy
module contains the various strategies as well
as some general-purpose methods for working with them. Within the context
of the brew livecheck
command, strategies are established procedures
for finding new software versions at a given source.
Defined Under Namespace
Classes: Apache, Bitbucket, Cpan, Git, GithubLatest, Gnome, Gnu, Hackage, HeaderMatch, Launchpad, Npm, PageMatch, Pypi, Sourceforge, Sparkle, Xorg
Class Method Summary collapse
- .from_symbol(symbol) ⇒ Strategy? private
-
.from_url(url, livecheck_strategy: nil, url_provided: nil, regex_provided: nil, block_provided: nil) ⇒ Array
private
Returns an array of strategies that apply to the provided URL.
-
.page_content(url) ⇒ Hash{Symbol => T.untyped}
private
Fetches the content at the URL and returns a hash containing the content and, if there are any redirections, the final URL.
-
.page_headers(url) ⇒ Object
private
Class Method Details
.from_symbol(symbol) ⇒ Strategy?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the Homebrew::Livecheck::Strategy that corresponds to the provided Symbol
(or
nil
if there is no matching Homebrew::Livecheck::Strategy).
50 51 52 |
# File 'brew/Library/Homebrew/livecheck/strategy.rb', line 50 def from_symbol(symbol) strategies[symbol] end |
.from_url(url, livecheck_strategy: nil, url_provided: nil, regex_provided: nil, block_provided: nil) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an array of strategies that apply to the provided URL.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'brew/Library/Homebrew/livecheck/strategy.rb', line 62 def from_url(url, livecheck_strategy: nil, url_provided: nil, regex_provided: nil, block_provided: nil) usable_strategies = strategies.values.select do |strategy| if strategy == PageMatch # Only treat the `PageMatch` strategy as usable if a regex is # present in the `livecheck` block next if !regex_provided && !block_provided elsif strategy.const_defined?(:PRIORITY) && !strategy::PRIORITY.positive? && from_symbol(livecheck_strategy) != strategy # Ignore strategies with a priority of 0 or lower, unless the # strategy is specified in the `livecheck` block next end strategy.respond_to?(:match?) && strategy.match?(url) end # Sort usable strategies in descending order by priority, using the # DEFAULT_PRIORITY when a strategy doesn't contain a PRIORITY constant usable_strategies.sort_by do |strategy| (strategy.const_defined?(:PRIORITY) ? -strategy::PRIORITY : -DEFAULT_PRIORITY) end end |
.page_content(url) ⇒ Hash{Symbol => T.untyped}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetches the content at the URL and returns a hash containing the content and, if there are any redirections, the final URL.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'brew/Library/Homebrew/livecheck/strategy.rb', line 126 def self.page_content(url) original_url = url # Manually handling `URI#open` redirections allows us to detect the # resolved URL while also supporting HTTPS to HTTP redirections (which # are normally forbidden by `OpenURI`). begin content = URI.parse(url).open(redirect: false, &:read) rescue OpenURI::HTTPRedirect => e url = e.uri.to_s retry end data = { content: content } data[:final_url] = url unless url == original_url data end |
.page_headers(url) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'brew/Library/Homebrew/livecheck/strategy.rb', line 86 def self.page_headers(url) headers = [] [:default, :browser].each do |user_agent| args = [ "--head", # Only work with the response headers "--request", "GET", # Use a GET request (instead of HEAD) "--silent", # Silent mode "--location", # Follow redirects "--connect-timeout", "5", # Max time allowed for connection (secs) "--max-time", "10" # Max time allowed for transfer (secs) ] stdout, _, status = curl_with_workarounds( *args, url, print_stdout: false, print_stderr: false, debug: false, verbose: false, user_agent: user_agent, retry: false ) while stdout.match?(/\AHTTP.*\r$/) h, stdout = stdout.split("\r\n\r\n", 2) headers << h.split("\r\n").drop(1) .map { |header| header.split(/:\s*/, 2) } .to_h.transform_keys(&:downcase) end return headers if status.success? end headers end |