-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
/
installer.rb
31 lines (28 loc) · 1.08 KB
/
installer.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
class Cask::DSL::Installer
VALID_KEYS = Set.new [
:manual,
:script,
]
attr_accessor *VALID_KEYS
def initialize(*parameters)
unless parameters.length > 0
raise CaskInvalidError.new(self.token, "'installer' stanza requires an argument")
end
parameters = Hash.new().merge(*parameters)
if parameters.key?(:script) and ! parameters[:script].respond_to?(:key?)
if parameters.key?(:executable)
raise CaskInvalidError.new(self.token, "'installer' stanza gave arguments for both :script and :executable")
end
parameters[:executable] = parameters[:script]
parameters.delete(:script)
parameters = { :script => parameters }
end
unless parameters.keys.length == 1
raise "invalid 'installer' stanza: only one of #{VALID_KEYS.inspect} is permitted"
end
key = parameters.keys.first
raise "invalid 'installer' stanza key: '#{key.inspect}'" unless VALID_KEYS.include?(key)
writer_method = "#{key}=".to_sym
send(writer_method, parameters[key])
end
end