Browse Source

rework Cask.path so it can return hypothetical paths

introduces the concept of a default_tap which is where we assume cask
paths that do not exist will end up

this is plumbing to support the incoming `cask edit foo --create`
feature
phinze 12 years ago
parent
commit
0fbe7a1a8d
  1. 28
      lib/cask.rb
  2. 3
      test/test_helper.rb

28
lib/cask.rb

@ -29,7 +29,15 @@ class Cask
def self.appdir=(_appdir)
@appdir = _appdir
end
def self.default_tap
@default_tap ||= 'phinze-cask'
end
def self.default_tap=(_tap)
@default_tap = _tap
end
def self.init
HOMEBREW_CACHE.mkpath unless HOMEBREW_CACHE.exist?
caskroom.mkpath unless caskroom.exist?
@ -37,13 +45,25 @@ class Cask
end
def self.path(cask_title)
cask_title = all_titles.grep(/#{cask_title}$/).first unless cask_title =~ /\//
tapspath.join(cask_title.sub("/", "/Casks/") + ".rb") unless cask_title.nil?
if cask_title.include?('/')
cask_with_tap = cask_title
else
cask_with_tap = all_titles.grep(/#{cask_title}$/).first
end
if cask_with_tap
tap, cask = cask_with_tap.split('/')
tapspath.join(tap, 'Casks', "#{cask}.rb")
else
tapspath.join(default_tap, 'Casks', "#{cask_title}.rb")
end
end
def self.load(cask_title)
cask_path = path(cask_title)
raise CaskUnavailableError, cask_title unless cask_path
unless cask_path.exist?
raise CaskUnavailableError, cask_title
end
require cask_path
const_get(cask_title.split('/').last.split('-').map(&:capitalize).join).new
end

3
test/test_helper.rb

@ -26,6 +26,9 @@ require 'purdytest'
# our baby
require 'cask'
# look for casks in testscasks by default
Cask.default_tap = 'phinze-testcasks'
class TestHelper
# helper for test casks to reference local files easily
def self.local_binary(name)

Loading…
Cancel
Save