cask_loader: fixup artifacts/caveats from JSON API.

These are mapped to generic versions in `cask/cask.rb` so we need to map
them back for them to be correct.
This commit is contained in:
Mike McQuaid 2023-01-25 15:07:44 +00:00
parent 8f419180cf
commit ab1fbb7fa9
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829

View File

@ -218,6 +218,10 @@ module Cask
return FromContentLoader.new(cask_source).load(config: config) return FromContentLoader.new(cask_source).load(config: config)
end end
# convert generic string replacements into actual ones
json_cask[:artifacts] = json_cask[:artifacts].map(&method(:from_h_hash_gsubs))
json_cask[:caveats] = from_h_string_gsubs(json_cask[:caveats])
Cask.new(token, source: cask_source, config: config) do Cask.new(token, source: cask_source, config: config) do
version json_cask[:version] version json_cask[:version]
@ -286,6 +290,38 @@ module Cask
caveats json_cask[:caveats] if json_cask[:caveats].present? caveats json_cask[:caveats] if json_cask[:caveats].present?
end end
end end
private
def from_h_string_gsubs(string)
string.to_s
.gsub("$HOME", Dir.home)
.gsub("$(brew --prefix)", HOMEBREW_PREFIX)
end
def from_h_array_gsubs(array)
array.to_a.map do |value|
from_h_gsubs(value)
end
end
def from_h_hash_gsubs(hash)
hash.to_h.transform_values do |value|
from_h_gsubs(value)
end
rescue TypeError
from_h_array_gsubs(hash)
end
def from_h_gsubs(value)
if value.respond_to? :to_h
from_h_hash_gsubs(value)
elsif value.respond_to? :to_a
from_h_array_gsubs(value)
else
from_h_string_gsubs(value)
end
end
end end
# Pseudo-loader which raises an error when trying to load the corresponding cask. # Pseudo-loader which raises an error when trying to load the corresponding cask.