Allow Cask refs
This commit is contained in:
parent
a41f15ede7
commit
c799f5f818
@ -52,25 +52,28 @@ module Cask
|
|||||||
# Loads a cask from a string.
|
# Loads a cask from a string.
|
||||||
class FromContentLoader < AbstractContentLoader
|
class FromContentLoader < AbstractContentLoader
|
||||||
sig {
|
sig {
|
||||||
params(ref: T.any(Pathname, String, URI::Generic), warn: T::Boolean)
|
params(ref: T.any(Pathname, String, Cask, URI::Generic), warn: T::Boolean)
|
||||||
.returns(T.nilable(T.attached_class))
|
.returns(T.nilable(T.attached_class))
|
||||||
}
|
}
|
||||||
def self.try_new(ref, warn: false)
|
def self.try_new(ref, warn: false)
|
||||||
return if ref.is_a?(URI::Generic)
|
case ref
|
||||||
|
when Cask, URI::Generic
|
||||||
|
# do nothing
|
||||||
|
else
|
||||||
|
content = ref.to_str
|
||||||
|
|
||||||
content = ref.to_str
|
# Cache compiled regex
|
||||||
|
@regex ||= begin
|
||||||
|
token = /(?:"[^"]*"|'[^']*')/
|
||||||
|
curly = /\(\s*#{token.source}\s*\)\s*\{.*\}/
|
||||||
|
do_end = /\s+#{token.source}\s+do(?:\s*;\s*|\s+).*end/
|
||||||
|
/\A\s*cask(?:#{curly.source}|#{do_end.source})\s*\Z/m
|
||||||
|
end
|
||||||
|
|
||||||
# Cache compiled regex
|
return unless content.match?(@regex)
|
||||||
@regex ||= begin
|
|
||||||
token = /(?:"[^"]*"|'[^']*')/
|
new(content)
|
||||||
curly = /\(\s*#{token.source}\s*\)\s*\{.*\}/
|
|
||||||
do_end = /\s+#{token.source}\s+do(?:\s*;\s*|\s+).*end/
|
|
||||||
/\A\s*cask(?:#{curly.source}|#{do_end.source})\s*\Z/m
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless content.match?(@regex)
|
|
||||||
|
|
||||||
new(content)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(content: String, tap: Tap).void }
|
sig { params(content: String, tap: Tap).void }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user