Don't prefer Cask files in the cwd

Fixes #4641.  Cask files in the cwd are still permitted, but
at the very lowest priority, below Tapped Cask names.
This commit is contained in:
Roland Walker 2014-06-03 10:21:42 -04:00
parent db989c62f7
commit f8c9567a66
8 changed files with 53 additions and 33 deletions

View File

@ -221,12 +221,15 @@ above, a Cask name on the command line can take the form of:
* a Cask name as returned by `brew cask search`, _eg_: `google-chrome`
* a fully-qualified Cask name which includes the Tap, _eg_: `caskroom/fonts/font-symbola`
`brew cask` also accepts two other forms for Cask names:
`brew cask` also accepts three other forms for Cask names:
* a fully-qualified pathname to a Cask file, _eg_: `/usr/local/Cellar/brew-cask/0.25.0/Casks/google-chrome.rb`
* a path to a Cask file, _eg_: `/usr/local/Cellar/brew-cask/0.25.0/Casks/google-chrome.rb`
* a `curl`-retrievable URI to a Cask file, _eg_: `https://raw.github.com/caskroom/homebrew-cask/f54bbfaae0f2fa7210484f46313a459cb8a14d2f/Casks/google-chrome.rb`
* a file in the current working directory, _eg_: `my-modfied-google-chrome.rb`. Note
that Tapped Casks names will be preferred over this form. To force the use of a Cask
file in the current directory, specify a pathname with slashes, _eg_: `./google-chrome.rb`.
The last two forms are intended for users who wish to maintain private Casks.
The last three forms are intended for users who wish to maintain private Casks.
## Taps

View File

@ -1,7 +1,8 @@
module Cask::Source; end
require 'cask/source/gone'
require 'cask/source/path'
require 'cask/source/path_slash_required'
require 'cask/source/path_slash_optional'
require 'cask/source/tapped_qualified'
require 'cask/source/untapped_qualified'
require 'cask/source/tapped'
@ -11,10 +12,11 @@ module Cask::Source
def self.sources
[
Cask::Source::URI,
Cask::Source::Path,
Cask::Source::PathSlashRequired,
Cask::Source::TappedQualified,
Cask::Source::UntappedQualified,
Cask::Source::Tapped,
Cask::Source::PathSlashOptional,
Cask::Source::Gone,
]
end

View File

@ -1,26 +0,0 @@
class Cask::Source::Path
def self.me?(query)
query_with_ext = "#{query}"
query_with_ext.concat('.rb') unless query_with_ext.match(%r{\.rb\Z}i)
# bug? arguably, we should not pick up a relative path
# containing a Cask file so easily, since this source
# is tested before the default Tap. Perhaps there
# should be two Path sources, absolute and relative.
File.file?(query_with_ext)
end
attr_reader :path
def initialize(path)
@path = Pathname(path).expand_path
end
def load
require path
Cask.const_get(cask_class_name).new
end
def cask_class_name
path.basename.to_s.sub(/\.rb/, '').split('-').map(&:capitalize).join
end
end

View File

@ -0,0 +1,25 @@
class Cask::Source::PathBase
# derived classes must define method self.me?
def self.path_for_query(query)
path_string = "#{query}"
path_string.concat('.rb') unless path_string.match(%r{\.rb\Z}i)
Pathname.new(path_string)
end
attr_reader :path
def initialize(path)
@path = Pathname(path).expand_path
end
def load
require path
Cask.const_get(cask_class_name).new
end
def cask_class_name
path.basename.to_s.sub(/\.rb/, '').split('-').map(&:capitalize).join
end
end

View File

@ -0,0 +1,8 @@
require 'cask/source/path_base'
class Cask::Source::PathSlashOptional < Cask::Source::PathBase
def self.me?(query)
path = self.path_for_query(query)
path.exist?
end
end

View File

@ -0,0 +1,8 @@
require 'cask/source/path_base'
class Cask::Source::PathSlashRequired < Cask::Source::PathBase
def self.me?(query)
path = self.path_for_query(query)
path.to_s.include?('/') and path.exist?
end
end

View File

@ -25,6 +25,6 @@ class Cask::Source::Tapped
def load
path = self.class.path_for_query(title)
Cask::Source::Path.new(path).load
Cask::Source::PathSlashOptional.new(path).load
end
end

View File

@ -15,7 +15,7 @@ class Cask::Source::URI
ohai "Downloading #{uri}"
odebug "Download target -> #{path.to_s}"
curl(uri, '-o', path.to_s)
Cask::Source::Path.new(path).load
Cask::Source::PathSlashOptional.new(path).load
rescue ErrorDuringExecution
raise CaskUnavailableError, uri
end