2023-02-11 22:16:57 -08:00
|
|
|
# typed: true
|
2021-08-06 02:30:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Homebrew
|
|
|
|
module API
|
|
|
|
# Helper functions for using the formula JSON API.
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
module Formula
|
2021-08-09 16:48:13 -04:00
|
|
|
class << self
|
|
|
|
extend T::Sig
|
2021-08-06 02:30:44 -04:00
|
|
|
|
2021-08-09 16:48:13 -04:00
|
|
|
sig { params(name: String).returns(Hash) }
|
|
|
|
def fetch(name)
|
2022-12-30 02:24:12 -05:00
|
|
|
Homebrew::API.fetch "formula/#{name}.json"
|
2021-08-09 16:48:13 -04:00
|
|
|
end
|
2021-12-07 00:13:56 +00:00
|
|
|
|
2022-09-14 23:54:14 -04:00
|
|
|
sig { returns(Hash) }
|
2021-12-07 00:13:56 +00:00
|
|
|
def all_formulae
|
|
|
|
@all_formulae ||= begin
|
2022-12-30 01:01:52 -05:00
|
|
|
json_formulae = Homebrew::API.fetch_json_api_file "formula.json",
|
|
|
|
target: HOMEBREW_CACHE_API/"formula.json"
|
2021-12-07 00:13:56 +00:00
|
|
|
|
2022-09-14 23:54:14 -04:00
|
|
|
@all_aliases = {}
|
2021-12-07 00:13:56 +00:00
|
|
|
json_formulae.to_h do |json_formula|
|
2022-09-14 23:54:14 -04:00
|
|
|
json_formula["aliases"].each do |alias_name|
|
|
|
|
@all_aliases[alias_name] = json_formula["name"]
|
|
|
|
end
|
|
|
|
|
2021-12-07 00:13:56 +00:00
|
|
|
[json_formula["name"], json_formula.except("name")]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-09-14 23:54:14 -04:00
|
|
|
|
|
|
|
sig { returns(Hash) }
|
|
|
|
def all_aliases
|
|
|
|
all_formulae if @all_aliases.blank?
|
|
|
|
|
|
|
|
@all_aliases
|
|
|
|
end
|
2021-08-06 02:30:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|