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_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.
334 335 336 337 338 339 340 |
# File 'cask/cask_loader.rb', line 334 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.
305 306 307 |
# File 'cask/cask_loader.rb', line 305 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.
302 303 304 |
# File 'cask/cask_loader.rb', line 302 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.
299 300 301 |
# File 'cask/cask_loader.rb', line 299 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.
311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'cask/cask_loader.rb', line 311 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.
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 400 401 402 403 404 405 406 |
# File 'cask/cask_loader.rb', line 342 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, 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, } 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) api_cask end |