mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Don't convert boolean and blank values to strings in cask artifacts API
This commit is contained in:
parent
39e158fb93
commit
a166be9541
@ -292,14 +292,20 @@ module Cask
|
||||
artifacts.map do |artifact|
|
||||
next artifact.to_h if artifact.is_a? Artifact::AbstractFlightBlock
|
||||
|
||||
if artifact.is_a? Artifact::Relocated
|
||||
source, *args = artifact.to_args
|
||||
next { artifact.class.dsl_key => [to_h_string_gsubs(source, replace_prefix: false), *to_h_gsubs(args)] }
|
||||
end
|
||||
|
||||
{ artifact.class.dsl_key => to_h_gsubs(artifact.to_args) }
|
||||
end
|
||||
end
|
||||
|
||||
def to_h_string_gsubs(string)
|
||||
string.to_s
|
||||
.gsub(Dir.home, "$HOME")
|
||||
.gsub(HOMEBREW_PREFIX, "$(brew --prefix)")
|
||||
def to_h_string_gsubs(string, replace_prefix: true)
|
||||
string = string.to_s.gsub(Dir.home, "$HOME")
|
||||
return string unless replace_prefix
|
||||
|
||||
string.gsub(HOMEBREW_PREFIX, "$(brew --prefix)")
|
||||
end
|
||||
|
||||
def to_h_array_gsubs(array)
|
||||
@ -317,10 +323,14 @@ module Cask
|
||||
end
|
||||
|
||||
def to_h_gsubs(value)
|
||||
return value if value.blank?
|
||||
|
||||
if value.respond_to? :to_h
|
||||
to_h_hash_gsubs(value)
|
||||
elsif value.respond_to? :to_a
|
||||
to_h_array_gsubs(value)
|
||||
elsif [true, false].include? value
|
||||
value
|
||||
else
|
||||
to_h_string_gsubs(value)
|
||||
end
|
||||
|
@ -322,12 +322,14 @@ module Cask
|
||||
end
|
||||
|
||||
def from_h_gsubs(value)
|
||||
return value if value.blank?
|
||||
|
||||
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)
|
||||
{ "true" => true, "false" => false }.fetch(value, from_h_string_gsubs(value))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user