Merge pull request #833 from ShaneDelmore/cask-strategy
Issue #6 Load cask from url enhancement.
This commit is contained in:
commit
a5425e54d8
33
lib/cask.rb
33
lib/cask.rb
|
@ -1,5 +1,7 @@
|
|||
require 'uri'
|
||||
|
||||
HOMEBREW_CACHE_CASKS = HOMEBREW_CACHE.join('Casks')
|
||||
|
||||
class Cask; end
|
||||
class Cask::CLI; end
|
||||
|
||||
|
@ -41,8 +43,12 @@ class Cask
|
|||
@default_tap = _tap
|
||||
end
|
||||
|
||||
def self._file_source?(cask_title)
|
||||
File.file?(cask_title)
|
||||
def self._file_source?(requested_cask)
|
||||
File.file?(requested_cask)
|
||||
end
|
||||
|
||||
def self._uri_source?(requested_cask)
|
||||
!!(requested_cask =~ URI.regexp)
|
||||
end
|
||||
|
||||
def self.init
|
||||
|
@ -90,8 +96,17 @@ class Cask
|
|||
_load_from_file(source)
|
||||
end
|
||||
|
||||
def self._load_from_path(cask_title)
|
||||
_load_from_file(Pathname.new(File::expand_path(cask_title)))
|
||||
def self._load_from_path(cask_path)
|
||||
_load_from_file(Pathname.new(File::expand_path(cask_path)))
|
||||
end
|
||||
|
||||
def self._load_from_uri(url)
|
||||
HOMEBREW_CACHE_CASKS.mkpath
|
||||
path = HOMEBREW_CACHE_CASKS.join(File.basename(url))
|
||||
curl(url, '-o', path.to_s)
|
||||
_load_from_path(path.to_s)
|
||||
rescue ErrorDuringExecution
|
||||
raise CaskUnavailableError, url
|
||||
end
|
||||
|
||||
def self._load_from_file(source)
|
||||
|
@ -100,11 +115,13 @@ class Cask
|
|||
const_get(cask_class_name(source)).new
|
||||
end
|
||||
|
||||
def self.load(cask_title)
|
||||
if _file_source?(cask_title)
|
||||
_load_from_path(cask_title)
|
||||
def self.load(requested_cask)
|
||||
if _uri_source?(requested_cask)
|
||||
_load_from_uri(requested_cask)
|
||||
elsif _file_source?(requested_cask)
|
||||
_load_from_path(requested_cask)
|
||||
else
|
||||
_load_from_tap(cask_title)
|
||||
_load_from_tap(requested_cask)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,6 +15,20 @@ describe "Cask" do
|
|||
c.must_be_instance_of(Dia)
|
||||
end
|
||||
|
||||
it "returns an instance of the cask from a url" do
|
||||
url = "file://" + File.expand_path('./Casks/dia.rb')
|
||||
c = Cask.load(url)
|
||||
c.must_be_kind_of(Cask)
|
||||
c.must_be_instance_of(Dia)
|
||||
end
|
||||
|
||||
it "raises an error when failing to download a cask from a url" do
|
||||
lambda {
|
||||
url = "file://" + File.expand_path('./Casks/notacask.rb')
|
||||
Cask.load(url)
|
||||
}.must_raise(CaskUnavailableError)
|
||||
end
|
||||
|
||||
it "returns an instance of the cask from a relative file location" do
|
||||
c = Cask.load("./Casks/dia.rb")
|
||||
c.must_be_kind_of(Cask)
|
||||
|
|
Loading…
Reference in New Issue