Class: Cask::CaskLoader::FromURILoader

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

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

Returns a new instance of FromURILoader



87
88
89
90
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 87

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

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url



85
86
87
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 85

def url
  @url
end

Class Method Details

.can_load?(ref) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
83
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 80

def self.can_load?(ref)
  uri_regex = ::URI::DEFAULT_PARSER.make_regexp
  ref.to_s.match?(Regexp.new('\A' + uri_regex.source + '\Z', uri_regex.options))
end

Instance Method Details

#loadObject



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

def load
  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