Skip to content

Commit

Permalink
Partially support pour_bottle? in API
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Dec 7, 2023
1 parent ab6a7ed commit fe011ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,7 @@ def to_hash
"revision" => revision,
"version_scheme" => version_scheme,
"bottle" => {},
"pour_bottle_only_if" => self.class.pour_bottle_only_if&.to_s,
"keg_only" => keg_only?,
"keg_only_reason" => keg_only_reason&.to_hash,
"options" => [],
Expand Down Expand Up @@ -3538,6 +3539,7 @@ def service(&block)
# <pre>pour_bottle? only_if: :clt_installed</pre>
def pour_bottle?(only_if: nil, &block)
@pour_bottle_check = PourBottleCheck.new(self)
@pour_bottle_only_if = only_if

if only_if.present? && block.present?
raise ArgumentError, "Do not pass both a preset condition and a block to `pour_bottle?`"
Expand Down Expand Up @@ -3571,6 +3573,9 @@ def pour_bottle?(only_if: nil, &block)
@pour_bottle_check.instance_eval(&block)
end

# @private
attr_reader :pour_bottle_only_if

# Deprecates a {Formula} (on the given date) so a warning is
# shown on each installation. If the date has not yet passed the formula
# will not be deprecated.
Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ def self.load_formula_from_api(name, flags:)
end
end

if (pour_bottle_only_if = json_formula["pour_bottle_only_if"])
pour_bottle? only_if: pour_bottle_only_if.to_sym
end

if (keg_only_reason = json_formula["keg_only_reason"].presence)
reason = Formulary.convert_to_string_or_symbol keg_only_reason["reason"]
keg_only reason, keg_only_reason["explanation"]
Expand Down

0 comments on commit fe011ca

Please sign in to comment.