Module: Homebrew::API::Formula Private

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.

Constant Summary collapse

MAX_RETRIES =

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

3

Class Method Summary collapse

Class Method Details

.all_aliasesHash

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:

  • (Hash)


65
66
67
68
69
# File 'api/formula.rb', line 65

def all_aliases
  all_formulae if @all_aliases.blank?

  @all_aliases
end

.all_formulaeHash

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:

  • (Hash)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'api/formula.rb', line 32

def all_formulae
  @all_formulae ||= begin
    retry_count = 0

    url = "https://formulae.brew.sh/api/formula.json"
    json_formulae = begin
      curl_args = %W[--compressed --silent #{url}]
      if cached_formula_json_file.exist? && !cached_formula_json_file.empty?
        curl_args.prepend("--time-cond", cached_formula_json_file)
      end
      curl_download(*curl_args, to: cached_formula_json_file, max_time: 5)

      JSON.parse(cached_formula_json_file.read)
    rescue JSON::ParserError
      cached_formula_json_file.unlink
      retry_count += 1
      odie "Cannot download non-corrupt #{url}!" if retry_count > MAX_RETRIES

      retry
    end

    @all_aliases = {}
    json_formulae.to_h do |json_formula|
      json_formula["aliases"].each do |alias_name|
        @all_aliases[alias_name] = json_formula["name"]
      end

      [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:



22
23
24
# File 'api/formula.rb', line 22

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)


27
28
29
# File 'api/formula.rb', line 27

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:



16
17
18
# File 'api/formula.rb', line 16

def formula_api_path
  "formula"
end