Class: Cask::CaskLoader::FromURILoader Private

Inherits:
FromPathLoader show all
Extended by:
T::Sig
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 FromContentLoader

#content

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:



109
110
111
112
# File 'cask/cask_loader.rb', line 109

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



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

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

Returns:

  • (Boolean)


95
96
97
98
99
100
101
102
103
104
# File 'cask/cask_loader.rb', line 95

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. 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
117
118
119
120
121
122
123
124
125
# File 'cask/cask_loader.rb', line 114

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