File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class CaskStruct < T::Struct
88 def self . from_hash ( cask_hash , ignore_types : false )
99 return super ( cask_hash ) if ignore_types
1010
11+ cask_hash = ::Cask ::Cask . deep_remove_placeholders ( cask_hash )
1112 cask_hash = cask_hash . transform_keys ( &:to_sym )
1213 . slice ( *decorator . all_props )
1314 . compact_blank
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ module API
99 class FormulaStruct < T ::Struct
1010 sig { params ( formula_hash : T ::Hash [ String , T . untyped ] ) . returns ( FormulaStruct ) }
1111 def self . from_hash ( formula_hash )
12+ formula_hash = ::Formula . deep_remove_placeholders ( formula_hash )
1213 formula_hash = formula_hash . transform_keys ( &:to_sym )
1314 . slice ( *decorator . all_props )
1415 . compact_blank
Original file line number Diff line number Diff line change @@ -38,4 +38,24 @@ def generating_hash?
3838 @generating_hash ||= false
3939 @generating_hash == true
4040 end
41+
42+ sig { type_parameters ( :U ) . params ( value : T . type_parameter ( :U ) ) . returns ( T . type_parameter ( :U ) ) }
43+ def deep_remove_placeholders ( value )
44+ return value if generating_hash?
45+
46+ value = case value
47+ when Hash
48+ value . transform_values { |v | deep_remove_placeholders ( v ) }
49+ when Array
50+ value . map { |v | deep_remove_placeholders ( v ) }
51+ when String
52+ value . gsub ( HOMEBREW_HOME_PLACEHOLDER , Dir . home )
53+ . gsub ( HOMEBREW_PREFIX_PLACEHOLDER , HOMEBREW_PREFIX )
54+ . gsub ( HOMEBREW_CELLAR_PLACEHOLDER , HOMEBREW_CELLAR )
55+ else
56+ value
57+ end
58+
59+ T . cast ( value , T . type_parameter ( :U ) )
60+ end
4161end
You can’t perform that action at this time.
0 commit comments