File tree 1 file changed +36
-1
lines changed
1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,42 @@ def load
19
19
raise CaskError . new "File '#{ path } ' is not readable" unless path . readable?
20
20
raise CaskError . new "File '#{ path } ' is not a plain file" unless path . file?
21
21
begin
22
- require path
22
+
23
+ # forward compatibility hack: convert first lines of the new form
24
+ #
25
+ # cask :v1 => 'google-chrome' do
26
+ #
27
+ # to the old form
28
+ #
29
+ # class GoogleChrome < Cask
30
+ #
31
+ # limitation: does not support Ruby extended quoting such as %Q{}
32
+ #
33
+ # in the future, this can be pared down to an "eval"
34
+
35
+ # read Cask
36
+ cask_string = File . open ( path , 'rb' ) do |handle |
37
+ contents = handle . read
38
+ if defined? ( Encoding )
39
+ contents . force_encoding ( 'UTF-8' )
40
+ else
41
+ contents
42
+ end
43
+ end
44
+
45
+ # munge text
46
+ cask_string . sub! ( %r{\A (\s *\# [^\n ]*\n )+} , '' ) ;
47
+ if %r{\A \s *cask\s +:v[\d _]+\s +=>\s +([\' \" ])(\S +?)\1 (?:\s *,\s *|\s +)do\s *\n } . match ( cask_string )
48
+ cask_string . sub! ( %r{\A [^\n ]+\n } , "class #{ cask_class_name } < Cask\n " )
49
+ end
50
+
51
+ # simulate "require"
52
+ begin
53
+ Cask . const_get ( cask_class_name )
54
+ rescue NameError
55
+ eval ( cask_string , TOPLEVEL_BINDING )
56
+ end
57
+
23
58
rescue CaskError , StandardError , ScriptError => e
24
59
# bug: e.message.concat doesn't work with CaskError exceptions
25
60
e . message . concat ( " while loading '#{ path } '" )
You can’t perform that action at this time.
0 commit comments