Class: Cask::CaskLoader::FromAPILoader Private
- Includes:
- ILoader
- Defined in:
- cask/cask_loader.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Loads a cask from the JSON API.
Instance Attribute Summary collapse
- #api_fallback ⇒ Boolean readonly private
- #from_json ⇒ Hash{String => T.untyped}? readonly private
- #path ⇒ Pathname readonly private
- #token ⇒ String readonly private
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(token, from_json: nil, path: nil, from_installed_caskfile: false, from_internal_json: false, api_fallback: true) ⇒ void constructor private
-
#load(config:) ⇒ Cask
private
This is a false positive incompatibililty warning, due to Kernel#load being overridden.
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(token, from_json: nil, path: nil, from_installed_caskfile: false, from_internal_json: false, api_fallback: true) ⇒ 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.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'cask/cask_loader.rb', line 300 def initialize(token, from_json: nil, path: nil, from_installed_caskfile: false, from_internal_json: false, api_fallback: true) @token = T.let(token.sub(%r{^homebrew/(?:homebrew-)?cask/}i, ""), String) sourcefile_path = if path path elsif from_json from_internal_json ? Homebrew::API::Internal.cached_packages_json_file_path : Homebrew::API::Cask.cached_json_file_path else Homebrew::API.cached_cask_json_file_path end @sourcefile_path = T.let(sourcefile_path, Pathname) path ||= CaskLoader.default_path(@token) @path = T.let(path, Pathname) @from_json = from_json @from_installed_caskfile = from_installed_caskfile @from_internal_json = from_internal_json @api_fallback = api_fallback end |
Instance Attribute Details
#api_fallback ⇒ Boolean (readonly)
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.
268 269 270 |
# File 'cask/cask_loader.rb', line 268 def api_fallback @api_fallback end |
#from_json ⇒ Hash{String => T.untyped}? (readonly)
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.
265 266 267 |
# File 'cask/cask_loader.rb', line 265 def from_json @from_json end |
#path ⇒ Pathname (readonly)
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.
262 263 264 |
# File 'cask/cask_loader.rb', line 262 def path @path end |
#token ⇒ String (readonly)
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.
259 260 261 |
# File 'cask/cask_loader.rb', line 259 def token @token end |
Class Method Details
.try_new(ref, warn: false) ⇒ FromAPILoader?
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.
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'cask/cask_loader.rb', line 274 def self.try_new(ref, warn: false) return unless CoreCaskTap.instance.use_api? return unless (token = ref[HOMEBREW_DEFAULT_TAP_CASK_REGEX, :token]) if !Homebrew::API.cask_token?(token) && !Homebrew::API.cask_renames.key?(token) return end ref = "#{CoreCaskTap.instance}/#{token}" return unless (token_tap_type = CaskLoader.tap_cask_token_type(ref, warn:)) token, tap, = token_tap_type new("#{tap}/#{token}") end |
Instance Method Details
#load(config:) ⇒ Cask
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 is a false positive incompatibililty warning, due to Kernel#load being overridden.
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'cask/cask_loader.rb', line 321 def load(config:) api_source = from_json if api_source.nil? cask_struct = Homebrew::API::Internal.cask_struct(token) api_source = Homebrew::API::Internal.cask_hash(token) raise KeyError, "key not found: #{token.inspect}" if api_source.nil? tap_git_head = Homebrew::API::Internal.cask_tap_git_head load_from_struct(config:, cask_struct:, api_source:, tap_git_head:, internal_api: true) elsif @from_internal_json api_source = api_source.dup tap_git_head = api_source.delete("tap_git_head") cask_struct = Homebrew::API::CaskStruct.deserialize(api_source) load_from_struct(config:, cask_struct:, api_source:, tap_git_head:, internal_api: true) else if @from_installed_caskfile api_source = api_source.dup api_source["version"] = api_source["version"].presence api_source["version"] ||= @sourcefile_path.dirname.dirname.dirname.basename.to_s.presence installed_tab = CaskLoader.load_installed_tab(token) api_source["version"] ||= installed_tab.version.presence api_source["artifacts"] ||= CaskLoader.resolve_installed_artifacts( token, installed_tab.uninstall_artifacts, tap: installed_tab.tap, api_fallback: @api_fallback ) if api_source.dig("depends_on", "formula").blank? && (formula_deps = Hash.try_convert(installed_tab.runtime_dependencies) &.transform_keys(&:to_s) &.fetch("formula", nil)).is_a?(Array) api_source["depends_on"] = (api_source["depends_on"] || {}).merge( "formula" => formula_deps.filter_map do |dep| dep["full_name"] if dep.is_a?(Hash) && dep["declared_directly"] end, ) end end tap_git_head = api_source["tap_git_head"] cask_struct = Homebrew::API::Cask::CaskStructGenerator.generate_cask_struct_hash( api_source, ignore_types: @from_installed_caskfile ) load_from_struct(config:, cask_struct:, api_source:, tap_git_head:) end end |