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
- #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: T.unsafe(nil), path: nil, from_installed_caskfile: false) ⇒ void constructor private
- #load(config:) ⇒ Object private
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) ⇒ 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.
355 356 357 358 359 360 361 |
# File 'cask/cask_loader.rb', line 355 def initialize(token, from_json: T.unsafe(nil), path: nil, from_installed_caskfile: false) @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 @from_installed_caskfile = from_installed_caskfile end |
Instance Attribute Details
#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.
326 327 328 |
# File 'cask/cask_loader.rb', line 326 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.
323 324 325 |
# File 'cask/cask_loader.rb', line 323 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.
320 321 322 |
# File 'cask/cask_loader.rb', line 320 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.
332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'cask/cask_loader.rb', line 332 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.
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 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'cask/cask_loader.rb', line 363 def load(config:) json_cask = from_json json_cask ||= Homebrew::API::Cask.all_casks.fetch(token) cask_struct = Homebrew::API::Cask::CaskStructGenerator.generate_cask_struct_hash( json_cask, ignore_types: @from_installed_caskfile ) = { loaded_from_api: true, api_source: json_cask, sourcefile_path: @sourcefile_path, source: JSON.pretty_generate(json_cask), config:, loader: self, } tap_git_head = json_cask["tap_git_head"] if (tap_string = cask_struct.tap_string) [:tap] = Tap.fetch(tap_string) end api_cask = Cask.new(token, **) 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 if 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.})" 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, tap_git_head:) api_cask end |