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
Instance Attribute Summary collapse
- #from_installed_caskfile ⇒ void writeonly private
- #path ⇒ Pathname readonly private
- #token ⇒ String 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: nil) ⇒ void constructor private
- #load(config:) ⇒ Cask private
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(path, token: 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.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'cask/cask_loader.rb', line 120 def initialize(path, token: nil) super() path = Pathname(path). @token = T.let(CaskLoader.token_from_path(path), String) @path = T.let(path, Pathname) @tap = T.let(Tap.from_path(path), T.nilable(Tap)) @from_installed_caskfile = T.let(false, T::Boolean) @api_fallback = T.let(true, T::Boolean) end |
Instance Attribute Details
#from_installed_caskfile=(value) ⇒ void (writeonly)
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.
This method returns an undefined value.
117 118 119 |
# File 'cask/cask_loader.rb', line 117 def from_installed_caskfile=(value) @from_installed_caskfile = value 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.
114 115 116 |
# File 'cask/cask_loader.rb', line 114 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.
111 112 113 |
# File 'cask/cask_loader.rb', line 111 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.
103 104 105 106 107 108 |
# File 'cask/cask_loader.rb', line 103 def self.invalid_path?(pathname, valid_extnames: %w[.rb .json]) return true if valid_extnames.exclude?(pathname.extname) @invalid_basenames ||= T.let(%w[INSTALL_RECEIPT.json sbom.spdx.json].freeze, T.nilable(T::Array[String])) @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.
97 98 99 100 |
# File 'cask/cask_loader.rb', line 97 def self.try_new(_ref, warn: false) CaskLoader.odeprecated "Cask::CaskLoader::FromPathLoader.try_new", "Cask::CaskLoader.from_path" nil 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.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'cask/cask_loader.rb', line 133 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? source_tap = tap if path.extname == ".rb" Homebrew::Trust.require_trusted_cask!(token, path, tap: source_tap) @content = path.read(encoding: "UTF-8") @config = config if !self.class.invalid_path?(path, valid_extnames: %w[.json]) && (from_json = JSON.parse(@content)) && from_json.is_a?(Hash) && (@from_installed_caskfile || from_json.present?) begin from_internal_json = path.to_s.end_with?(".internal.json") return FromAPILoader.new( token, from_json:, path:, from_installed_caskfile: @from_installed_caskfile, from_internal_json:, api_fallback: @api_fallback, ).load(config:) rescue CaskInvalidError => e if @from_installed_caskfile error = CaskUnreadableError.new(token, e.reason) error.set_backtrace e.backtrace raise error end raise end end begin ENV.clear_sensitive_environment_for_eval! do cask = instance_eval(content, path.to_s) raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.") unless cask.is_a?(Cask) cask end rescue NameError, ArgumentError, ScriptError => e error = CaskUnreadableError.new(token, e.) error.set_backtrace e.backtrace raise error rescue CaskInvalidError => e # e.g. NoMethodError from removed DSL methods, wrapped # as CaskInvalidError by Cask#refresh before reaching here. if @from_installed_caskfile error = CaskUnreadableError.new(token, e.reason) error.set_backtrace e.backtrace raise error end raise end end |