Class: Cask::CaskLoader::FromURILoader Private

Inherits:
FromPathLoader show all
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 URI.

Instance Attribute Summary collapse

Attributes inherited from FromPathLoader

#path, #token

Attributes inherited from AbstractContentLoader

#content, #tap

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FromPathLoader

invalid_path?

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(url) ⇒ 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.

Parameters:



204
205
206
207
208
# File 'cask/cask_loader.rb', line 204

def initialize(url)
  @url = URI(url)
  @name = File.basename(T.must(@url.path))
  super Cache.path/name
end

Instance Attribute Details

#nameObject (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.



201
202
203
# File 'cask/cask_loader.rb', line 201

def name
  @name
end

#urlObject (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.



201
202
203
# File 'cask/cask_loader.rb', line 201

def url
  @url
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.

Parameters:

Returns:

  • (T.attached_class, nil)


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'cask/cask_loader.rb', line 183

def self.try_new(ref, warn: false)
  return if Homebrew::EnvConfig.forbid_packages_from_paths?

  # Cache compiled regex
  @uri_regex ||= begin
    uri_regex = ::URI::RFC2396_PARSER.make_regexp
    Regexp.new("\\A#{uri_regex.source}\\Z", uri_regex.options)
  end

  uri = ref.to_s
  return unless uri.match?(@uri_regex)

  uri = URI(uri)
  return unless uri.path

  new(uri)
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.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'cask/cask_loader.rb', line 210

def load(config:)
  path.dirname.mkpath

  if ALLOWED_URL_SCHEMES.exclude?(url.scheme)
    raise UnsupportedInstallationMethod,
          "Non-checksummed download of #{name} formula file from an arbitrary URL is unsupported! " \
          "`brew extract` or `brew create` and `brew tap-new` to create a formula file in a tap " \
          "on GitHub instead."
  end

  begin
    ohai "Downloading #{url}"
    ::Utils::Curl.curl_download url.to_s, to: path
  rescue ErrorDuringExecution
    raise CaskUnavailableError.new(token, "Failed to download #{Formatter.url(url)}.")
  end

  super
end