Extract latest_version string to a constant
This commit is contained in:
parent
f2fbbfe70c
commit
f03a400e28
@ -3278,6 +3278,7 @@ class Formula
|
||||
def livecheck(&block)
|
||||
return @livecheck unless block
|
||||
|
||||
include Homebrew::Livecheck::Constants
|
||||
@livecheckable = true
|
||||
@livecheck.instance_eval(&block)
|
||||
end
|
||||
|
@ -1,6 +1,8 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "livecheck/constants"
|
||||
|
||||
# The {Livecheck} class implements the DSL methods used in a formula's, cask's
|
||||
# or resource's `livecheck` block and stores related instance variables. Most
|
||||
# of these methods also return the related instance variable when no argument
|
||||
@ -142,13 +144,6 @@ class Livecheck
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a placeholder string that will be replaced with a formula's latest
|
||||
# version in livecheck URLs for its resources.
|
||||
# @return String
|
||||
def latest_version
|
||||
"<FORMULA_LATEST_VERSION>"
|
||||
end
|
||||
|
||||
delegate version: :@package_or_resource
|
||||
delegate arch: :@package_or_resource
|
||||
private :version, :arch
|
||||
|
14
Library/Homebrew/livecheck/constants.rb
Normal file
14
Library/Homebrew/livecheck/constants.rb
Normal file
@ -0,0 +1,14 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Homebrew
|
||||
module Livecheck
|
||||
# The {Constants} module provides constants that are intended to be used
|
||||
# in `livecheck` block values (e.g. `url`, `regex`).
|
||||
module Constants
|
||||
# A placeholder string used in resource `livecheck` block URLs that will
|
||||
# be replaced with the latest version from the main formula check.
|
||||
LATEST_VERSION = "<FORMULA_LATEST_VERSION>"
|
||||
end
|
||||
end
|
||||
end
|
@ -1,6 +1,7 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "livecheck/constants"
|
||||
require "livecheck/error"
|
||||
require "livecheck/livecheck_version"
|
||||
require "livecheck/skip_conditions"
|
||||
@ -877,7 +878,7 @@ module Homebrew
|
||||
checked_urls = []
|
||||
# rubocop:disable Metrics/BlockLength
|
||||
urls.each_with_index do |original_url, i|
|
||||
url = original_url.gsub(/<FORMULA_LATEST_VERSION>/, formula_latest)
|
||||
url = original_url.gsub(Constants::LATEST_VERSION, formula_latest)
|
||||
|
||||
# Only preprocess the URL when it's appropriate
|
||||
url = preprocess_url(url) unless STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL.include?(livecheck_strategy)
|
||||
|
Loading…
x
Reference in New Issue
Block a user