Class: Cask::CaskLoader::FromAPILoader Private
- Inherits:
-
Object
- Object
- Cask::CaskLoader::FromAPILoader
- 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.
Constant Summary collapse
- FLIGHT_STANZAS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
[:preflight, :postflight, :uninstall_preflight, :uninstall_postflight].freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
private
-
#token ⇒ Object
readonly
private
Class Method Summary collapse
-
.can_load?(ref) ⇒ Boolean
private
Instance Method Summary collapse
-
#initialize(token) ⇒ FromAPILoader
constructor
private
A new instance of FromAPILoader.
-
#load(config:) ⇒ Object
private
Constructor Details
#initialize(token) ⇒ FromAPILoader
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.
Returns a new instance of FromAPILoader.
199 200 201 202 |
# File 'cask/cask_loader.rb', line 199 def initialize(token) @token = token @path = CaskLoader.default_path(token) 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.
191 192 193 |
# File 'cask/cask_loader.rb', line 191 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.
191 192 193 |
# File 'cask/cask_loader.rb', line 191 def token @token end |
Class Method Details
.can_load?(ref) ⇒ 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.
195 196 197 |
# File 'cask/cask_loader.rb', line 195 def self.can_load?(ref) Homebrew::API::Cask.all_casks.key? ref 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.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'cask/cask_loader.rb', line 204 def load(config:) json_cask = Homebrew::API::Cask.all_casks[token] if (bottle_tag = ::Utils::Bottles.tag.to_s.presence) && (variations = json_cask["variations"].presence) && (variation = variations[bottle_tag].presence) json_cask = json_cask.merge(variation) end json_cask.deep_symbolize_keys! # Use the cask-source API if there are any `*flight` blocks if json_cask[:artifacts].any? { |artifact| FLIGHT_STANZAS.include?(artifact.keys.first) } cask_source = Homebrew::API::CaskSource.fetch(token) return FromContentLoader.new(cask_source).load(config: config) end # convert generic string replacements into actual ones json_cask[:artifacts] = json_cask[:artifacts].map(&method(:from_h_hash_gsubs)) json_cask[:caveats] = from_h_string_gsubs(json_cask[:caveats]) Cask.new(token, source: cask_source, config: config) do version json_cask[:version] if json_cask[:sha256] == "no_check" sha256 :no_check else sha256 json_cask[:sha256] end url json_cask[:url] appcast json_cask[:appcast] if json_cask[:appcast].present? json_cask[:name].each do |cask_name| name cask_name end desc json_cask[:desc] homepage json_cask[:homepage] auto_updates json_cask[:auto_updates] if json_cask[:auto_updates].present? conflicts_with(**json_cask[:conflicts_with]) if json_cask[:conflicts_with].present? if json_cask[:depends_on].present? dep_hash = json_cask[:depends_on].to_h do |dep_key, dep_value| # Arch dependencies are encoded like `{ type: :intel, bits: 64 }` # but `depends_on arch:` only accepts `:intel` or `:arm64` if dep_key == :arch next [:arch, :intel] if dep_value.first[:type] == "intel" next [:arch, :arm64] end next [dep_key, dep_value] unless dep_key == :macos dep_type = dep_value.keys.first if dep_type == :== version_symbols = dep_value[dep_type].map do |version| MacOSVersions::SYMBOLS.key(version) || version end next [dep_key, version_symbols] end version_symbol = dep_value[dep_type].first version_symbol = MacOSVersions::SYMBOLS.key(version_symbol) || version_symbol [dep_key, "#{dep_type} :#{version_symbol}"] end.compact depends_on(**dep_hash) end if json_cask[:container].present? container_hash = json_cask[:container].to_h do |container_key, container_value| next [container_key, container_value] unless container_key == :type [container_key, container_value.to_sym] end container(**container_hash) end json_cask[:artifacts].each do |artifact| key = artifact.keys.first if FLIGHT_STANZAS.include?(key) instance_eval(artifact[key]) else send(key, *artifact[key]) end end caveats json_cask[:caveats] if json_cask[:caveats].present? end end |