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 cask JSON API.
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
module Cask
|
2021-08-09 16:48:13 -04:00
|
|
|
class << self
|
|
|
|
extend T::Sig
|
2021-08-06 02:30:44 -04:00
|
|
|
|
2023-01-28 02:15:00 -06:00
|
|
|
sig { params(token: String).returns(Hash) }
|
|
|
|
def fetch(token)
|
|
|
|
Homebrew::API.fetch "cask/#{token}.json"
|
|
|
|
end
|
|
|
|
|
|
|
|
sig { params(token: String, git_head: T.nilable(String)).returns(String) }
|
|
|
|
def fetch_source(token, git_head: nil)
|
|
|
|
Homebrew::API.fetch_file_source "Casks/#{token}.rb", repo: "Homebrew/homebrew-cask", git_head: git_head
|
2021-08-09 16:48:13 -04:00
|
|
|
end
|
2022-12-29 02:48:31 -05:00
|
|
|
|
|
|
|
sig { returns(Hash) }
|
|
|
|
def all_casks
|
|
|
|
@all_casks ||= begin
|
2023-01-02 13:03:57 -05:00
|
|
|
json_casks = Homebrew::API.fetch_json_api_file "cask.json",
|
|
|
|
target: HOMEBREW_CACHE_API/"cask.json"
|
2022-12-29 02:48:31 -05:00
|
|
|
|
|
|
|
json_casks.to_h do |json_cask|
|
|
|
|
[json_cask["token"], json_cask.except("token")]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-08-06 02:30:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|