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

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:



175
176
177
178
# File 'cask/cask_loader.rb', line 175

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

Instance Attribute Details

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



172
173
174
# File 'cask/cask_loader.rb', line 172

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)


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'cask/cask_loader.rb', line 156

def self.try_new(ref, warn: false)
  # Cache compiled regex
  @uri_regex ||= begin
    uri_regex = ::URI::DEFAULT_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.



180
181
182
183
184
185
186
187
188
189
190
191
# File 'cask/cask_loader.rb', line 180

def load(config:)
  path.dirname.mkpath

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

  super
end