Class: Cask::CaskLoader::FromNameLoader Private

Inherits:
FromTapLoader show all
Extended by:
Utils::Output::Mixin
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.

Loader which tries loading casks from tap paths, failing if the same token exists in multiple taps.

Instance Attribute Summary

Attributes inherited from FromTapLoader

#tap

Attributes inherited from FromPathLoader

#from_installed_caskfile, #path, #token

Attributes inherited from AbstractContentLoader

#content, #tap

Class Method Summary collapse

Methods included from Utils::Output::Mixin

issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_uninstalled, pretty_unmarked, pretty_upgradable, pretty_warning

Methods inherited from FromTapLoader

#initialize, #load, loader_from_token_tap_type

Methods inherited from FromPathLoader

#initialize, invalid_path?, #load

Methods inherited from AbstractContentLoader

#initialize

Methods included from ILoader

#load

Constructor Details

This class inherits a constructor from Cask::CaskLoader::FromTapLoader

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:



590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
# File 'cask/cask_loader.rb', line 590

def self.try_new(ref, warn: false)
  return unless ref.is_a?(String)
  return unless ref.match?(/\A#{HOMEBREW_TAP_CASK_TOKEN_REGEX}\Z/o)

  token = ref.downcase

  # If it exists in the default tap, never treat it as ambiguous with another tap.
  if (core_cask_tap = CoreCaskTap.instance).installed? && (token_tap_type = CaskLoader.tap_cask_token_type(
    "#{core_cask_tap}/#{token}", warn: false
  ))
    migrated_token, migrated_tap, type = token_tap_type

    if warn && [:rename, :migration].include?(type) &&
       !(type == :migration && migrated_tap.core_tap?)
      opoo "Cask #{token} was renamed to " \
           "#{migrated_tap.core_cask_tap? ? migrated_token : "#{migrated_tap}/#{migrated_token}"}."
    end

    if (core_cask_loader = loader_from_token_tap_type(token_tap_type))&.path&.exist?
      return core_cask_loader
    end
  end

  loaders = Tap.select { |tap| tap.installed? && !tap.core_cask_tap? }
               .filter_map { |tap| super("#{tap}/#{token}", warn:) }
               .uniq(&:path)
               .select { |loader| loader.is_a?(FromAPILoader) || loader.path.exist? }

  case loaders.count
  when 1
    loaders.first
  when 2..Float::INFINITY
    raise TapCaskAmbiguityError.new(token, loaders)
  end
end