homebrew-cask/lib/cask.rb

67 lines
1.4 KiB
Ruby
Raw Normal View History

require 'uri'
class Cask; end
2012-11-19 02:27:14 +08:00
class Cask::CLI; end
libdir = File.dirname(__FILE__)
rubyfiles = Dir[File.join(libdir, '**', '*.rb')]
rubyfiles.each do |file|
require file.sub(/^#{libdir}\/(.*).rb$/, '\1')
end
class Cask
include Cask::Actions
include Cask::DSL
include Cask::Scopes
def self.tapspath
HOMEBREW_PREFIX.join "Library", "Taps"
end
def self.cellarpath
HOMEBREW_CELLAR
end
def self.appdir
@appdir ||= Pathname.new(File.expand_path("~/Applications"))
end
def self.init
HOMEBREW_CACHE.mkpath unless HOMEBREW_CACHE.exist?
appdir.mkpath unless appdir.exist?
end
def self.path(cask_title)
2012-11-19 13:10:28 +08:00
cask_title = all_titles.grep(/#{cask_title}$/).first unless cask_title =~ /\//
tapspath.join(cask_title.sub("/", "/Casks/") + ".rb") unless cask_title.nil?
end
def self.load(cask_title)
cask_path = path(cask_title)
raise CaskUnavailableError, cask_title unless cask_path
require cask_path
const_get(cask_title.split('/').last.split('-').map(&:capitalize).join).new
end
def self.title
self.name.gsub(/([a-z\d])([A-Z])/,'\1-\2').downcase
end
attr_reader :title
def initialize(title=self.class.title)
@title = title
end
def destination_path
HOMEBREW_CELLAR.join(self.title).join(self.version)
end
def installed?
destination_path.exist?
end
def to_s
@title
end
end