mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Add unversioned?
method to Cask::URL
.
This commit is contained in:
parent
ff28d7c69b
commit
76a3c0338b
@ -173,12 +173,14 @@ module Cask
|
||||
@language_blocks.keys.flatten
|
||||
end
|
||||
|
||||
def url(*args)
|
||||
set_unique_stanza(:url, args.empty? && !block_given?) do
|
||||
def url(*args, **options)
|
||||
caller_location = caller_locations[0]
|
||||
|
||||
set_unique_stanza(:url, args.empty? && options.empty? && !block_given?) do
|
||||
if block_given?
|
||||
LazyObject.new { URL.new(*yield) }
|
||||
LazyObject.new { URL.new(*yield, caller_location: caller_location) }
|
||||
else
|
||||
URL.new(*args)
|
||||
URL.new(*args, **options, caller_location: caller_location)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,19 +18,20 @@ class URL
|
||||
|
||||
sig do
|
||||
params(
|
||||
uri: T.any(URI::Generic, String),
|
||||
verified: T.nilable(String),
|
||||
using: T.nilable(Symbol),
|
||||
tag: T.nilable(String),
|
||||
branch: T.nilable(String),
|
||||
revisions: T.nilable(T::Array[String]),
|
||||
revision: T.nilable(String),
|
||||
trust_cert: T.nilable(T::Boolean),
|
||||
cookies: T.nilable(T::Hash[String, String]),
|
||||
referer: T.nilable(T.any(URI::Generic, String)),
|
||||
header: T.nilable(String),
|
||||
user_agent: T.nilable(T.any(Symbol, String)),
|
||||
data: T.nilable(T::Hash[String, String]),
|
||||
uri: T.any(URI::Generic, String),
|
||||
verified: T.nilable(String),
|
||||
using: T.nilable(Symbol),
|
||||
tag: T.nilable(String),
|
||||
branch: T.nilable(String),
|
||||
revisions: T.nilable(T::Array[String]),
|
||||
revision: T.nilable(String),
|
||||
trust_cert: T.nilable(T::Boolean),
|
||||
cookies: T.nilable(T::Hash[String, String]),
|
||||
referer: T.nilable(T.any(URI::Generic, String)),
|
||||
header: T.nilable(String),
|
||||
user_agent: T.nilable(T.any(Symbol, String)),
|
||||
data: T.nilable(T::Hash[String, String]),
|
||||
caller_location: Thread::Backtrace::Location,
|
||||
).returns(T.untyped)
|
||||
end
|
||||
def initialize(
|
||||
@ -46,8 +47,10 @@ class URL
|
||||
referer: nil,
|
||||
header: nil,
|
||||
user_agent: nil,
|
||||
data: nil
|
||||
data: nil,
|
||||
caller_location: T.must(caller_locations).fetch(0)
|
||||
)
|
||||
|
||||
@uri = URI(uri)
|
||||
|
||||
specs = {}
|
||||
@ -65,5 +68,29 @@ class URL
|
||||
specs[:data] = @data = data
|
||||
|
||||
@specs = specs.compact
|
||||
|
||||
@caller_location = caller_location
|
||||
end
|
||||
|
||||
sig { returns(T.nilable(String)) }
|
||||
def raw_interpolated_url
|
||||
return @raw_interpolated_url if defined?(@raw_interpolated_url)
|
||||
|
||||
@raw_interpolated_url =
|
||||
Pathname(@caller_location.absolute_path)
|
||||
.each_line.drop(@caller_location.lineno - 1)
|
||||
.first&.yield_self { |line| line[/url\s+"([^"]+)"/, 1] }
|
||||
end
|
||||
private :raw_interpolated_url
|
||||
|
||||
sig { params(ignore_major_version: T::Boolean).returns(T::Boolean) }
|
||||
def unversioned?(ignore_major_version: false)
|
||||
interpolated_url = raw_interpolated_url
|
||||
|
||||
return false unless interpolated_url
|
||||
|
||||
interpolated_url = interpolated_url.gsub(/\#{\s*version\s*\.major\s*}/, "") if ignore_major_version
|
||||
|
||||
interpolated_url.exclude?('#{')
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user