Add additional method signatures to strategies

This commit is contained in:
Sam Ford 2021-08-10 18:24:51 -04:00
parent 7e07010f06
commit f2bd39ccef
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
14 changed files with 27 additions and 2 deletions

View File

@ -86,6 +86,7 @@ module Homebrew
# At present, this should only be called after tap strategies have been # At present, this should only be called after tap strategies have been
# loaded, otherwise livecheck won't be able to use them. # loaded, otherwise livecheck won't be able to use them.
# @return [Hash] # @return [Hash]
sig { returns(T::Hash[Symbol, T.untyped]) }
def strategies def strategies
return @strategies if defined? @strategies return @strategies if defined? @strategies
@ -107,8 +108,9 @@ module Homebrew
# @param symbol [Symbol] the strategy name in snake case as a `Symbol` # @param symbol [Symbol] the strategy name in snake case as a `Symbol`
# (e.g. `:page_match`) # (e.g. `:page_match`)
# @return [Strategy, nil] # @return [Strategy, nil]
sig { params(symbol: T.nilable(Symbol)).returns(T.nilable(T.untyped)) }
def from_symbol(symbol) def from_symbol(symbol)
strategies[symbol] strategies[symbol] if symbol.present?
end end
# Returns an array of strategies that apply to the provided URL. # Returns an array of strategies that apply to the provided URL.
@ -119,7 +121,16 @@ module Homebrew
# @param regex_provided [Boolean] whether a regex is provided in the # @param regex_provided [Boolean] whether a regex is provided in the
# `livecheck` block # `livecheck` block
# @return [Array] # @return [Array]
def from_url(url, livecheck_strategy: nil, url_provided: nil, regex_provided: nil, block_provided: nil) sig {
params(
url: String,
livecheck_strategy: T.nilable(Symbol),
url_provided: T::Boolean,
regex_provided: T::Boolean,
block_provided: T::Boolean,
).returns(T::Array[T.untyped])
}
def from_url(url, livecheck_strategy: nil, url_provided: false, regex_provided: false, block_provided: false)
usable_strategies = strategies.values.select do |strategy| usable_strategies = strategies.values.select do |strategy|
if strategy == PageMatch if strategy == PageMatch
# Only treat the `PageMatch` strategy as usable if a regex is # Only treat the `PageMatch` strategy as usable if a regex is
@ -143,6 +154,7 @@ module Homebrew
end end
end end
sig { params(url: String).returns(T::Array[T::Hash[String, String]]) }
def self.page_headers(url) def self.page_headers(url)
headers = [] headers = []

View File

@ -37,6 +37,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -44,6 +44,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -35,6 +35,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -50,6 +50,7 @@ module Homebrew
# @param url [String] the URL of the Git repository to check # @param url [String] the URL of the Git repository to check
# @param regex [Regexp] the regex to use for filtering tags # @param regex [Regexp] the regex to use for filtering tags
# @return [Hash] # @return [Hash]
sig { params(url: String, regex: T.nilable(Regexp)).returns(T::Hash[Symbol, T.untyped]) }
def self.tag_info(url, regex = nil) def self.tag_info(url, regex = nil)
# Open3#capture3 is used here because we need to capture stderr # Open3#capture3 is used here because we need to capture stderr
# output and handle it in an appropriate manner. Alternatives like # output and handle it in an appropriate manner. Alternatives like

View File

@ -52,6 +52,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -40,6 +40,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -44,6 +44,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) && url.exclude?("savannah.") URL_MATCH_REGEX.match?(url) && url.exclude?("savannah.")
end end

View File

@ -37,6 +37,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -35,6 +35,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -31,6 +31,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -41,6 +41,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -47,6 +47,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end

View File

@ -64,6 +64,7 @@ module Homebrew
# #
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
sig { params(url: String).returns(T::Boolean) }
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) URL_MATCH_REGEX.match?(url)
end end