Module: Homebrew::API::Formula Private

Extended by:
T::Sig
Defined in:
api/formula.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper functions for using the formula JSON API.

Class Method Summary collapse

Class Method Details

.all_formulaeArray

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Array)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'api/formula.rb', line 30

def all_formulae
  @all_formulae ||= begin
    curl_args = %w[--compressed --silent https://formulae.brew.sh/api/formula.json]
    if cached_formula_json_file.exist?
      last_modified = cached_formula_json_file.mtime.utc
      last_modified = last_modified.strftime("%a, %d %b %Y %H:%M:%S GMT")
      curl_args = ["--header", "If-Modified-Since: #{last_modified}", *curl_args]
    end
    curl_download(*curl_args, to: HOMEBREW_CACHE_API/"#{formula_api_path}.json", max_time: 5)

    json_formulae = JSON.parse(cached_formula_json_file.read)

    json_formulae.to_h do |json_formula|
      [json_formula["name"], json_formula.except("name")]
    end
  end
end

.cached_formula_json_fileString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



20
21
22
# File 'api/formula.rb', line 20

def cached_formula_json_file
  HOMEBREW_CACHE_API/"#{formula_api_path}.json"
end

.fetch(name) ⇒ Hash

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Hash)


25
26
27
# File 'api/formula.rb', line 25

def fetch(name)
  Homebrew::API.fetch "#{formula_api_path}/#{name}.json"
end

.formula_api_pathString Also known as: generic_formula_api_path

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



14
15
16
# File 'api/formula.rb', line 14

def formula_api_path
  "formula"
end