Merge pull request #14503 from Rylan12/artifact-json-fix
Don't convert boolean and blank values to strings in cask artifacts API
This commit is contained in:
commit
0229196ac5
@ -295,16 +295,24 @@ module Cask
|
|||||||
|
|
||||||
def artifacts_list
|
def artifacts_list
|
||||||
artifacts.map do |artifact|
|
artifacts.map do |artifact|
|
||||||
next artifact.to_h if artifact.is_a? Artifact::AbstractFlightBlock
|
case artifact
|
||||||
|
when Artifact::AbstractFlightBlock
|
||||||
|
artifact.to_h
|
||||||
|
when Artifact::Relocated
|
||||||
|
# Don't replace the Homebrew prefix in the source path since the source could include /usr/local
|
||||||
|
source, *args = artifact.to_args
|
||||||
|
{ artifact.class.dsl_key => [to_h_string_gsubs(source, replace_prefix: false), *to_h_gsubs(args)] }
|
||||||
|
else
|
||||||
{ artifact.class.dsl_key => to_h_gsubs(artifact.to_args) }
|
{ artifact.class.dsl_key => to_h_gsubs(artifact.to_args) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def to_h_string_gsubs(string)
|
def to_h_string_gsubs(string, replace_prefix: true)
|
||||||
string.to_s
|
string = string.to_s.gsub(Dir.home, "$HOME")
|
||||||
.gsub(Dir.home, "$HOME")
|
return string unless replace_prefix
|
||||||
.gsub(HOMEBREW_PREFIX, "$(brew --prefix)")
|
|
||||||
|
string.gsub(HOMEBREW_PREFIX, "$(brew --prefix)")
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_h_array_gsubs(array)
|
def to_h_array_gsubs(array)
|
||||||
@ -322,10 +330,14 @@ module Cask
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_h_gsubs(value)
|
def to_h_gsubs(value)
|
||||||
|
return value if value.blank?
|
||||||
|
|
||||||
if value.respond_to? :to_h
|
if value.respond_to? :to_h
|
||||||
to_h_hash_gsubs(value)
|
to_h_hash_gsubs(value)
|
||||||
elsif value.respond_to? :to_a
|
elsif value.respond_to? :to_a
|
||||||
to_h_array_gsubs(value)
|
to_h_array_gsubs(value)
|
||||||
|
elsif [true, false].include? value
|
||||||
|
value
|
||||||
else
|
else
|
||||||
to_h_string_gsubs(value)
|
to_h_string_gsubs(value)
|
||||||
end
|
end
|
||||||
|
@ -328,12 +328,14 @@ module Cask
|
|||||||
end
|
end
|
||||||
|
|
||||||
def from_h_gsubs(value)
|
def from_h_gsubs(value)
|
||||||
|
return value if value.blank?
|
||||||
|
|
||||||
if value.respond_to? :to_h
|
if value.respond_to? :to_h
|
||||||
from_h_hash_gsubs(value)
|
from_h_hash_gsubs(value)
|
||||||
elsif value.respond_to? :to_a
|
elsif value.respond_to? :to_a
|
||||||
from_h_array_gsubs(value)
|
from_h_array_gsubs(value)
|
||||||
else
|
else
|
||||||
from_h_string_gsubs(value)
|
{ "true" => true, "false" => false }.fetch(value, from_h_string_gsubs(value))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user