33 lines
622 B
Ruby
Raw Normal View History

2016-09-24 13:52:43 +02:00
module Hbc
module Source
class URI
def self.me?(query)
!(query.to_s =~ ::URI.regexp).nil?
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
attr_reader :uri
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def initialize(uri)
@uri = uri
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def load
Hbc.cache.mkpath
path = Hbc.cache.join(File.basename(uri))
ohai "Downloading #{uri}"
odebug "Download target -> #{path}"
begin
curl(uri, "-o", path.to_s)
rescue ErrorDuringExecution
raise CaskUnavailableError, uri
end
PathSlashOptional.new(path).load
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def to_s
uri.to_s
end
end
2016-08-18 22:11:42 +03:00
end
end