forked from Homebrew/homebrew-cask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcask.rb
112 lines (91 loc) · 2.5 KB
/
cask.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require 'uri'
class Cask; end
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::DSL
include Cask::Scopes
def self.tapspath
HOMEBREW_PREFIX.join "Library", "Taps"
end
def self.caskroom
@@caskroom ||= Pathname('/opt/homebrew-cask/Caskroom')
end
def self.caskroom=(caskroom)
@@caskroom = caskroom
end
def self.appdir
@appdir ||= Pathname.new(File.expand_path("~/Applications"))
end
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?
unless caskroom.exist?
ohai "We need to make Caskroom for the first time at #{caskroom}"
ohai "We'll set permissions properly so this is the only time homebrew-cask will ever need sudo"
current_user = ENV['USER']
system "sudo mkdir -p #{caskroom}"
system "sudo chown -R #{current_user}:staff #{caskroom.parent}"
end
appdir.mkpath unless appdir.exist?
end
def self.path(cask_title)
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)
unless cask_path.exist?
raise CaskUnavailableError, cask_title
end
require cask_path
const_get(cask_title.split('/').last.split('-').map(&:capitalize).join).new
end
def self.title
self.name.gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').downcase
end
attr_reader :title
def initialize(title=self.class.title)
@title = title
end
def destination_path
self.class.caskroom.join(self.title).join(self.version)
end
def installed?
destination_path.exist?
end
def linkable_apps
if linkables.has_key? :app
linkables[:app].map { |app| Pathname.glob("#{destination_path}/**/#{app}").first }
else
Pathname.glob("#{destination_path}/**/*.app")
end
end
def installable_pkgs
installables.map { |pkg| Pathname.glob("#{destination_path}/**/#{pkg}").first }
end
def to_s
@title
end
end