Class: Cask::CaskLoader::FromURILoader Private

Inherits:
FromPathLoader show all
Defined in:
Library/Homebrew/cask/cask_loader.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Loads a cask from a URI.

Instance Attribute Summary collapse

Attributes inherited from FromPathLoader

#path, #token

Attributes inherited from FromContentLoader

#content

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ FromURILoader

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FromURILoader.


106
107
108
109
# File 'Library/Homebrew/cask/cask_loader.rb', line 106

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

Instance Attribute Details

#urlObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


104
105
106
# File 'Library/Homebrew/cask/cask_loader.rb', line 104

def url
  @url
end

Class Method Details

.can_load?(ref) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

93
94
95
96
97
98
99
100
101
102
# File 'Library/Homebrew/cask/cask_loader.rb', line 93

def self.can_load?(ref)
  uri_regex = ::URI::DEFAULT_PARSER.make_regexp
  return false unless ref.to_s.match?(Regexp.new("\\A#{uri_regex.source}\\Z", uri_regex.options))

  uri = URI(ref)
  return false unless uri
  return false unless uri.path

  true
end

Instance Method Details

#load(config:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


111
112
113
114
115
116
117
118
119
120
121
122
# File 'Library/Homebrew/cask/cask_loader.rb', line 111

def load(config:)
  path.dirname.mkpath

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

  super
end