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_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled

Constructor Details

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


331
332
333
334
335
336
# File 'cask/cask_loader.rb', line 331

def initialize(token, from_json: T.unsafe(nil), path: nil)
  @token = token.sub(%r{^homebrew/(?:homebrew-)?cask/}i, "")
  @sourcefile_path = path || Homebrew::API.cached_cask_json_file_path
  @path = path || CaskLoader.default_path(@token)
  @from_json = from_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:



303
304
305
# File 'cask/cask_loader.rb', line 303

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:



300
301
302
# File 'cask/cask_loader.rb', line 300

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:



297
298
299
# File 'cask/cask_loader.rb', line 297

def token
  @token
end

Class Method Details

.try_new(ref, warn: false) ⇒ T.attached_class?

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:

  • (T.attached_class, nil)


309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'cask/cask_loader.rb', line 309

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:) ⇒ Object

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.



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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'cask/cask_loader.rb', line 338

def load(config:)
  json_cask = from_json
  json_cask ||= if Homebrew::EnvConfig.use_internal_api?
    Homebrew::API::Internal.cask_hashes.fetch(token)
  else
    Homebrew::API::Cask.all_casks.fetch(token)
  end

  cask_struct = Homebrew::API::Cask.generate_cask_struct_hash(json_cask)

  cask_options = {
    loaded_from_api: true,
    api_source:      json_cask,
    sourcefile_path: @sourcefile_path,
    source:          JSON.pretty_generate(json_cask),
    config:,
    loader:          self,
    tap:             Tap.fetch(cask_struct.tap_string),
  }

  api_cask = Cask.new(token, **cask_options) do
    version cask_struct.version
    sha256 cask_struct.sha256

    url(*cask_struct.url_args, **cask_struct.url_kwargs)
    cask_struct.names.each do |cask_name|
      name cask_name
    end
    desc cask_struct.desc if cask_struct.desc?
    homepage cask_struct.homepage

    deprecate!(**cask_struct.deprecate_args) if cask_struct.deprecate?
    disable!(**cask_struct.disable_args) if cask_struct.disable?

    auto_updates cask_struct.auto_updates if cask_struct.auto_updates?
    conflicts_with(**cask_struct.conflicts_with_args) if cask_struct.conflicts?

    cask_struct.renames.each do |from, to|
      rename from, to
    end

    if cask_struct.depends_on?
      args = cask_struct.depends_on_args
      begin
        depends_on(**args)
      rescue MacOSVersion::Error => e
        odebug "Ignored invalid macOS version dependency in cask '#{token}': #{args.inspect} (#{e.message})"
        nil
      end
    end

    container(**cask_struct.container_args) if cask_struct.container?

    cask_struct.artifacts(appdir:).each do |key, args, kwargs, block|
      send(key, *args, **kwargs, &block)
    end

    caveats cask_struct.caveats(appdir:) if cask_struct.caveats?
  end
  api_cask.populate_from_api!(cask_struct)
  api_cask
end