Class: Cask::CaskLoader::FromAPILoader Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled

Constructor Details

#initialize(token, from_json: T.unsafe(nil), path: nil, from_installed_caskfile: false, from_internal_json: 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.

Parameters:

  • token (String)
  • from_json (Hash{String => T.untyped}, nil) (defaults to: T.unsafe(nil))
  • path (Pathname, nil) (defaults to: nil)
  • from_installed_caskfile (Boolean) (defaults to: false)
  • from_internal_json (Boolean) (defaults to: false)


397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'cask/cask_loader.rb', line 397

def initialize(token, from_json: T.unsafe(nil), path: nil, from_installed_caskfile: false,
               from_internal_json: false)
  @token = T.let(token.sub(%r{^homebrew/(?:homebrew-)?cask/}i, ""), String)
  @sourcefile_path = T.let(
    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,
    Pathname,
  )
  @path = T.let(path || CaskLoader.default_path(@token), Pathname)
  @from_json = from_json
  @from_installed_caskfile = from_installed_caskfile
  @from_internal_json = from_internal_json
end

Instance Attribute Details

#from_jsonHash{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.

Returns:



367
368
369
# File 'cask/cask_loader.rb', line 367

def from_json
  @from_json
end

#pathPathname (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.

Returns:



364
365
366
# File 'cask/cask_loader.rb', line 364

def path
  @path
end

#tokenString (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.

Returns:



361
362
363
# File 'cask/cask_loader.rb', line 361

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.

Parameters:

Returns:



373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'cask/cask_loader.rb', line 373

def self.try_new(ref, warn: false)
  return if Homebrew::EnvConfig.no_install_from_api?
  return unless ref.is_a?(String)
  return unless (token = ref[HOMEBREW_DEFAULT_TAP_CASK_REGEX, :token])
  if Homebrew::API.cask_tokens.exclude?(token) &&
     !Homebrew::API.cask_renames.key?(token)
    return
  end

  ref = "#{CoreCaskTap.instance}/#{token}"

  token, tap, = CaskLoader.tap_cask_token_type(ref, warn:)
  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.

Parameters:

Returns:



418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'cask/cask_loader.rb', line 418

def load(config:)
  if (api_source = from_json)
    if @from_internal_json
      load_from_internal_json(config:, api_source:)
    else
      load_from_json(config:, api_source:)
    end
  elsif Homebrew::EnvConfig.use_internal_api?
    load_from_internal_api(config:)
  else
    load_from_api(config:)
  end
end