Module: Homebrew::API::Internal Private

Extended by:
Cachable, T::Generic
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.

Constant Summary collapse

Cache =

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.

type_template { { fixed: T::Hash[String, T.untyped] } }

Class Method Summary collapse

Methods included from Cachable

cache, clear_cache

Class Method Details

.cached_packages_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_packages_json_file_path
  HOMEBREW_CACHE_API/packages_endpoint
end

.cask_hash(name) ⇒ 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.

Parameters:

Returns:



284
285
286
287
288
289
290
291
292
293
294
# File 'api/internal.rb', line 284

def self.cask_hash(name)
  ensure_cask_data!
  return cache["cask_hashes"][name] if cache.key?("cask_hashes")

  begin
    cache["packages_index"].cask_hash(name)
  rescue Homebrew::API::PackagesIndex::Invalid
    materialize_packages_index!
    cache["cask_hashes"][name]
  end
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:



276
277
278
279
280
281
# File 'api/internal.rb', line 276

def self.cask_hashes
  ensure_cask_data!
  materialize_packages_index! unless cache.key?("cask_hashes")

  cache["cask_hashes"]
end

.cask_name?(name) ⇒ 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:

  • (Boolean)


305
306
307
308
309
310
# File 'api/internal.rb', line 305

def self.cask_name?(name)
  ensure_cask_data!
  return cache["cask_hashes"].key?(name) if cache.key?("cask_hashes")

  cache["packages_index"].cask_name?(name)
end

.cask_namesArray<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:



297
298
299
300
301
302
# File 'api/internal.rb', line 297

def self.cask_names
  ensure_cask_data!
  return cache["cask_hashes"].keys if cache.key?("cask_hashes")

  cache["packages_index"].cask_names
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:



313
314
315
316
# File 'api/internal.rb', line 313

def self.cask_renames
  ensure_cask_data!
  packages_value("cask_renames")
end

.cask_struct(name) ⇒ Homebrew::API::CaskStruct

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:



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'api/internal.rb', line 50

def self.cask_struct(name)
  return cache["cask_structs"][name] if cache.key?("cask_structs") && cache["cask_structs"].key?(name)

  hash = cask_hash(name)
  raise "No cask found for #{name}" unless hash

  struct = Homebrew::API::CaskStruct.deserialize(hash)

  cache["cask_structs"] ||= {}
  cache["cask_structs"][name] = struct

  struct
end

.cask_tap_git_headString

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:



325
326
327
328
# File 'api/internal.rb', line 325

def self.cask_tap_git_head
  ensure_cask_data!
  packages_value("cask_tap_git_head")
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:



319
320
321
322
# File 'api/internal.rb', line 319

def self.cask_tap_migrations
  ensure_cask_data!
  packages_value("cask_tap_migrations")
end

.fetch_packages_api!(download_queue: nil, stale_seconds: nil, enqueue: false) ⇒ Array<([Hash{String => T.untyped}, Homebrew::API::PackagesIndex], 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:

  • download_queue (DownloadQueueType) (defaults to: nil)
  • stale_seconds (Integer, nil) (defaults to: nil)
  • enqueue (Boolean) (defaults to: false)

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'api/internal.rb', line 73

def self.fetch_packages_api!(download_queue: nil, stale_seconds: nil, enqueue: false)
  old_failed = Homebrew.failed?
  json_contents, updated = begin
    cached_packages_index(stale_seconds:, enqueue:) ||
      Homebrew::API.fetch_json_api_file(packages_endpoint, stale_seconds:, download_queue:, enqueue:)
  rescue ErrorDuringExecution => e
    raise if e.stderr.exclude?("HTTP status: 404") || effective_tag == fallback_tag

    @effective_tag = fallback_tag
    Homebrew.failed = old_failed
    retry
  end

  [T.cast(json_contents, T.any(T::Hash[String, T.untyped], Homebrew::API::PackagesIndex)), 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:



252
253
254
255
# File 'api/internal.rb', line 252

def self.formula_aliases
  ensure_formula_data!
  packages_value("formula_aliases")
end

.formula_hash(name) ⇒ 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.

Parameters:

Returns:



223
224
225
226
227
228
229
230
231
232
233
# File 'api/internal.rb', line 223

def self.formula_hash(name)
  ensure_formula_data!
  return cache["formula_hashes"][name] if cache.key?("formula_hashes")

  begin
    cache["packages_index"].formula_hash(name)
  rescue Homebrew::API::PackagesIndex::Invalid
    materialize_packages_index!
    cache["formula_hashes"][name]
  end
end

.formula_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:



215
216
217
218
219
220
# File 'api/internal.rb', line 215

def self.formula_hashes
  ensure_formula_data!
  materialize_packages_index! unless cache.key?("formula_hashes")

  cache["formula_hashes"]
end

.formula_hashes_cached?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.

Whether internal packages API data is already loaded, as full hashes or a byte-offset index, so callers can use it opportunistically without triggering a download and full JSON parse.

Returns:

  • (Boolean)


210
211
212
# File 'api/internal.rb', line 210

def self.formula_hashes_cached?
  data_loaded?
end

.formula_name?(name) ⇒ 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:

  • (Boolean)


244
245
246
247
248
249
# File 'api/internal.rb', line 244

def self.formula_name?(name)
  ensure_formula_data!
  return cache["formula_hashes"].key?(name) if cache.key?("formula_hashes")

  cache["packages_index"].formula_name?(name)
end

.formula_namesArray<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:



236
237
238
239
240
241
# File 'api/internal.rb', line 236

def self.formula_names
  ensure_formula_data!
  return cache["formula_hashes"].keys if cache.key?("formula_hashes")

  cache["packages_index"].formula_names
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:



258
259
260
261
# File 'api/internal.rb', line 258

def self.formula_renames
  ensure_formula_data!
  packages_value("formula_renames")
end

.formula_struct(name) ⇒ Homebrew::API::FormulaStruct

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:



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'api/internal.rb', line 35

def self.formula_struct(name)
  return cache["formula_structs"][name] if cache.key?("formula_structs") && cache["formula_structs"].key?(name)

  hash = formula_hash(name)
  raise "No formula found for #{name}" unless hash

  struct = Homebrew::API::FormulaStruct.deserialize(hash, bottle_tag: effective_tag)

  cache["formula_structs"] ||= {}
  cache["formula_structs"][name] = struct

  struct
end

.formula_tap_git_headString

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:



270
271
272
273
# File 'api/internal.rb', line 270

def self.formula_tap_git_head
  ensure_formula_data!
  packages_value("formula_tap_git_head")
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:



264
265
266
267
# File 'api/internal.rb', line 264

def self.formula_tap_migrations
  ensure_formula_data!
  packages_value("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)


200
201
202
203
204
# File 'api/internal.rb', line 200

def self.write_cask_names(regenerate: false)
  download_and_cache_data! unless data_loaded?

  Homebrew::API.write_names_file!("cask", regenerate:) { cask_names }
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)


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

def self.write_formula_names_and_aliases(regenerate: false)
  download_and_cache_data! unless data_loaded?

  Homebrew::API.write_names_file!("formula", regenerate:) { formula_names }
  # Renames resolve like aliases in lightweight formula lookups.
  Homebrew::API.write_aliases_file!("formula", regenerate:) { formula_aliases.merge(formula_renames) }
  Homebrew::API.write_executables_file!(regenerate:, source: cached_packages_json_file_path) { formula_hashes }
end