Class: Cask::CaskLoader::FromPathLoader Private
- Inherits:
-
AbstractContentLoader
- Object
- AbstractContentLoader
- Cask::CaskLoader::FromPathLoader
- 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 a path.
Direct Known Subclasses
FromInstalledPathLoader, FromTapLoader, FromURILoader, NullLoader
Instance Attribute Summary collapse
- #path ⇒ Object readonly private
- #token ⇒ Object readonly private
Attributes inherited from AbstractContentLoader
Class Method Summary collapse
- .invalid_path?(pathname, valid_extnames: %w[.rb .json])) ⇒ Boolean private
- .try_new(ref, warn: false) ⇒ T.attached_class? private
Instance Method Summary collapse
- #initialize(path, token: T.unsafe(nil)) ⇒ void constructor private
- #load(config:) ⇒ Cask 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(path, token: T.unsafe(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.
133 134 135 136 137 138 139 140 141 |
# File 'cask/cask_loader.rb', line 133 def initialize(path, token: T.unsafe(nil)) super() path = Pathname(path). @token = path.basename(path.extname).to_s @path = path @tap = Tap.from_path(path) || Homebrew::API.tap_from_source_download(path) end |
Instance Attribute Details
#path ⇒ Object (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.
130 131 132 |
# File 'cask/cask_loader.rb', line 130 def path @path end |
#token ⇒ Object (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.
130 131 132 |
# File 'cask/cask_loader.rb', line 130 def token @token end |
Class Method Details
.invalid_path?(pathname, valid_extnames: %w[.rb .json])) ⇒ Boolean
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.
123 124 125 126 127 128 |
# File 'cask/cask_loader.rb', line 123 def self.invalid_path?(pathname, valid_extnames: %w[.rb .json]) return true if valid_extnames.exclude?(pathname.extname) @invalid_basenames ||= %w[INSTALL_RECEIPT.json sbom.spdx.json].freeze @invalid_basenames.include?(pathname.basename.to_s) end |
.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.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'cask/cask_loader.rb', line 103 def self.try_new(ref, warn: false) path = case ref when String Pathname(ref) when Pathname ref else return end return unless path..exist? return if invalid_path?(path) return if Homebrew::EnvConfig.forbid_packages_from_paths? && !path.realpath.to_s.start_with?("#{Caskroom.path}/", "#{HOMEBREW_LIBRARY}/Taps/") new(path) 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.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'cask/cask_loader.rb', line 144 def load(config:) raise CaskUnavailableError.new(token, "'#{path}' does not exist.") unless path.exist? raise CaskUnavailableError.new(token, "'#{path}' is not readable.") unless path.readable? raise CaskUnavailableError.new(token, "'#{path}' is not a file.") unless path.file? @content = path.read(encoding: "UTF-8") @config = config if !self.class.invalid_path?(path, valid_extnames: %w[.json]) && (from_json = JSON.parse(@content).presence) && from_json.is_a?(Hash) return FromAPILoader.new(token, from_json:, path:).load(config:) end begin instance_eval(content, path).tap do |cask| raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.") unless cask.is_a?(Cask) end rescue NameError, ArgumentError, ScriptError => e error = CaskUnreadableError.new(token, e.) error.set_backtrace e.backtrace raise error end end |