Sparkle: Reorganize methods, etc.
This commit is contained in:
parent
0148ee870e
commit
9fdc902630
@ -16,26 +16,13 @@ module Homebrew
|
|||||||
|
|
||||||
NICE_NAME = "Sparkle"
|
NICE_NAME = "Sparkle"
|
||||||
|
|
||||||
# Checks the content at the URL for new versions.
|
Item = Struct.new(:title, :url, :bundle_version, :short_version, :version, keyword_init: true) do
|
||||||
sig { params(url: String, regex: T.nilable(Regexp)).returns(T::Hash[Symbol, T.untyped]) }
|
extend T::Sig
|
||||||
def self.find_versions(url, regex, &block)
|
|
||||||
raise ArgumentError, "The #{name.demodulize} strategy does not support regular expressions." if regex
|
|
||||||
|
|
||||||
match_data = { matches: {}, regex: regex, url: url }
|
extend Forwardable
|
||||||
|
|
||||||
contents = Strategy.page_content(url)
|
delegate version: :bundle_version
|
||||||
|
delegate short_version: :bundle_version
|
||||||
if (item = item_from_content(contents))
|
|
||||||
match = if block
|
|
||||||
block.call(item)&.to_s
|
|
||||||
else
|
|
||||||
item.bundle_version&.nice_version
|
|
||||||
end
|
|
||||||
|
|
||||||
match_data[:matches][match] = Version.new(match) if match
|
|
||||||
end
|
|
||||||
|
|
||||||
match_data
|
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(content: String).returns(T.nilable(Item)) }
|
sig { params(content: String).returns(T.nilable(Item)) }
|
||||||
@ -80,13 +67,26 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
private_class_method :item_from_content
|
private_class_method :item_from_content
|
||||||
|
|
||||||
Item = Struct.new(:title, :url, :bundle_version, :short_version, :version, keyword_init: true) do
|
# Checks the content at the URL for new versions.
|
||||||
extend T::Sig
|
sig { params(url: String, regex: T.nilable(Regexp)).returns(T::Hash[Symbol, T.untyped]) }
|
||||||
|
def self.find_versions(url, regex, &block)
|
||||||
|
raise ArgumentError, "The #{name.demodulize} strategy does not support regular expressions." if regex
|
||||||
|
|
||||||
extend Forwardable
|
match_data = { matches: {}, regex: regex, url: url }
|
||||||
|
|
||||||
delegate version: :bundle_version
|
contents = Strategy.page_content(url)
|
||||||
delegate short_version: :bundle_version
|
|
||||||
|
if (item = item_from_content(contents))
|
||||||
|
match = if block
|
||||||
|
block.call(item)&.to_s
|
||||||
|
else
|
||||||
|
item.bundle_version&.nice_version
|
||||||
|
end
|
||||||
|
|
||||||
|
match_data[:matches][match] = Version.new(match) if match
|
||||||
|
end
|
||||||
|
|
||||||
|
match_data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user