Skip to content

Commit

Permalink
Merge pull request #16305 from Bo98/pour_bottle-api
Browse files Browse the repository at this point in the history
Partially support `pour_bottle?` in API
  • Loading branch information
MikeMcQuaid authored Dec 7, 2023
2 parents cd6f3fe + fe011ca commit 8b98411
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 8b98411

Please sign in to comment.