Skip to content

Commit 53c8c72

Browse files
committed
Remove API placeholders in FormulaStruct and CaskStruct
1 parent e7d847d commit 53c8c72

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

Library/Homebrew/api/cask_struct.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

Library/Homebrew/api/formula_struct.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

Library/Homebrew/api_hashable.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
Kernel.raise ArgumentError, "Cannot process value while generating hash" 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
4161
end

Library/Homebrew/dev-cmd/generate-formula-api.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def run
4848
latest_macos = MacOSVersion.new((HOMEBREW_MACOS_NEWEST_UNSUPPORTED.to_i - 1).to_s).to_sym
4949
Homebrew::SimulateSystem.with(os: latest_macos, arch: :arm) do
5050
tap.formula_names.each do |name|
51+
next unless name == "redis"
52+
5153
formula = Formulary.factory(name)
5254
name = formula.name
5355
all_formulae[name] = formula.to_hash_with_variations

0 commit comments

Comments
 (0)