Module: Homebrew::API::Internal Private

Extended by:
Cachable
Defined in:
api/internal.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 JSON internal API.

Class Method Summary collapse

Methods included from Cachable

cache, clear_cache

Class Method Details

.cached_cask_json_file_pathPathname

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:



65
66
67
# File 'api/internal.rb', line 65

def self.cached_cask_json_file_path
  HOMEBREW_CACHE_API/cask_endpoint
end

.cached_formula_json_file_pathPathname

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:



60
61
62
# File 'api/internal.rb', line 60

def self.cached_formula_json_file_path
  HOMEBREW_CACHE_API/formula_endpoint
end

.cask_endpointString

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:



24
25
26
# File 'api/internal.rb', line 24

def self.cask_endpoint
  "internal/cask.#{SimulateSystem.current_tag}.jws.json"
end

.cask_hashesHash{String => Hash{String => T.untyped}}

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:



168
169
170
171
172
173
174
175
# File 'api/internal.rb', line 168

def self.cask_hashes
  unless cache.key?("cask_hashes")
    updated = download_and_cache_cask_data!
    write_cask_names(regenerate: updated)
  end

  cache["cask_hashes"]
end

.cask_renamesHash{String => String}

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:



178
179
180
181
182
183
184
185
# File 'api/internal.rb', line 178

def self.cask_renames
  unless cache.key?("cask_renames")
    updated = download_and_cache_cask_data!
    write_cask_names(regenerate: updated)
  end

  cache["cask_renames"]
end

.cask_tap_migrationsHash{String => String}

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:



188
189
190
191
192
193
194
195
# File 'api/internal.rb', line 188

def self.cask_tap_migrations
  unless cache.key?("cask_tap_migrations")
    updated = download_and_cache_cask_data!
    write_cask_names(regenerate: updated)
  end

  cache["cask_tap_migrations"]
end

.fetch_cask_api!(download_queue: nil, stale_seconds: nil) ⇒ Array<(Hash{String => T.untyped}, Boolean)>

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:



82
83
84
85
# File 'api/internal.rb', line 82

def self.fetch_cask_api!(download_queue: nil, stale_seconds: nil)
  json_contents, updated = Homebrew::API.fetch_json_api_file(cask_endpoint, stale_seconds:, download_queue:)
  [T.cast(json_contents, T::Hash[String, T.untyped]), updated]
end

.fetch_formula_api!(download_queue: nil, stale_seconds: nil) ⇒ Array<(Hash{String => T.untyped}, Boolean)>

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:



73
74
75
76
# File 'api/internal.rb', line 73

def self.fetch_formula_api!(download_queue: nil, stale_seconds: nil)
  json_contents, updated = Homebrew::API.fetch_json_api_file(formula_endpoint, stale_seconds:, download_queue:)
  [T.cast(json_contents, T::Hash[String, T.untyped]), updated]
end

.formula_aliasesHash{String => String}

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:



138
139
140
141
142
143
144
145
# File 'api/internal.rb', line 138

def self.formula_aliases
  unless cache.key?("formula_aliases")
    updated = download_and_cache_formula_data!
    write_formula_names_and_aliases(regenerate: updated)
  end

  cache["formula_aliases"]
end

.formula_arraysHash{String => Array<(String, Integer, Integer, [String, nil])>}

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:



128
129
130
131
132
133
134
135
# File 'api/internal.rb', line 128

def self.formula_arrays
  unless cache.key?("formula_arrays")
    updated = download_and_cache_formula_data!
    write_formula_names_and_aliases(regenerate: updated)
  end

  cache["formula_arrays"]
end

.formula_endpointString

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:



19
20
21
# File 'api/internal.rb', line 19

def self.formula_endpoint
  "internal/formula.#{SimulateSystem.current_tag}.jws.json"
end

.formula_renamesHash{String => String}

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:



148
149
150
151
152
153
154
155
# File 'api/internal.rb', line 148

def self.formula_renames
  unless cache.key?("formula_renames")
    updated = download_and_cache_formula_data!
    write_formula_names_and_aliases(regenerate: updated)
  end

  cache["formula_renames"]
end

.formula_stub(name) ⇒ Homebrew::FormulaStub

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:



29
30
31
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
# File 'api/internal.rb', line 29

def self.formula_stub(name)
  return cache["formula_stubs"][name] if cache.key?("formula_stubs") && cache["formula_stubs"].key?(name)

  stub_array = formula_arrays[name]
  raise "No formula stub found for #{name}" unless stub_array

  aliases = formula_aliases.filter_map do |alias_name, original_name|
    alias_name if original_name == name
  end

  oldnames = formula_renames.filter_map do |oldname, newname|
    oldname if newname == name
  end

  stub = Homebrew::FormulaStub.new(
    name:           name,
    pkg_version:    PkgVersion.parse(stub_array[0]),
    version_scheme: stub_array[1],
    rebuild:        stub_array[2],
    sha256:         stub_array[3],
    aliases:,
    oldnames:,
  )

  cache["formula_stubs"] ||= {}
  cache["formula_stubs"][name] = stub

  stub
end

.formula_tap_migrationsHash{String => String}

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:



158
159
160
161
162
163
164
165
# File 'api/internal.rb', line 158

def self.formula_tap_migrations
  unless cache.key?("formula_tap_migrations")
    updated = download_and_cache_formula_data!
    write_formula_names_and_aliases(regenerate: updated)
  end

  cache["formula_tap_migrations"]
end

.write_cask_names(regenerate: false) ⇒ void

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.

This method returns an undefined value.

Parameters:

  • regenerate (Boolean) (defaults to: false)


121
122
123
124
125
# File 'api/internal.rb', line 121

def self.write_cask_names(regenerate: false)
  download_and_cache_cask_data! unless cache.key?("cask_hashes")

  Homebrew::API.write_names_file!(cask_hashes.keys, "cask", regenerate:)
end

.write_formula_names_and_aliases(regenerate: false) ⇒ void

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.

This method returns an undefined value.

Parameters:

  • regenerate (Boolean) (defaults to: false)


113
114
115
116
117
118
# File 'api/internal.rb', line 113

def self.write_formula_names_and_aliases(regenerate: false)
  download_and_cache_formula_data! unless cache.key?("formula_arrays")

  Homebrew::API.write_names_file!(formula_arrays.keys, "formula", regenerate:)
  Homebrew::API.write_aliases_file!(formula_aliases, "formula", regenerate:)
end