Class: Hbc::CaskLoader::FromURILoader

Inherits:
FromPathLoader show all
Defined in:
Library/Homebrew/cask/lib/hbc/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



77
78
79
80
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 77

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

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url



75
76
77
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 75

def url
  @url
end

Class Method Details

.can_load?(ref) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 70

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



82
83
84
85
86
87
88
89
90
91
92
93
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 82

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