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
|
# File 'lib/middleman-cdn/commands.rb', line 25
def cdn_invalidate(*args)
begin
options, files = if args.first && args.first.respond_to?(:filter)
[args.first, args.drop(1)]
else
[Middleman::CDN::Extension.options, args]
end
if options.nil?
self.class.say_status(nil, ANSI.red{ "Error: You need to activate the cdn extension in config.rb.\n#{example_configuration}" })
return
end
options.filter ||= /.*/
if cdns.all? { |cdn| options.public_send(cdn.key.to_sym).nil? }
self.class.say_status(nil, ANSI.red{ "Error: You must specify a config for one of the supported CDNs.\n#{example_configuration}" })
raise
end
unless files.empty?
files = normalize_files(files)
message = "Invalidating #{files.count} files:"
else
files = normalize_files(list_files(options.filter))
message = "Invalidating #{files.count} files with filter: #{options.filter.source}"
end
self.class.say_status(nil, message)
files.each { |file| self.class.say_status(nil, " • #{file}") }
return if files.empty?
invalidate_all = does_filter_match_all(options.filter)
cdns_keyed.each do |cdn_key, cdn|
cdn_options = options.public_send(cdn_key.to_sym)
cdn.new.invalidate(cdn_options, files, all: invalidate_all) unless cdn_options.nil?
end
rescue SystemExit, Interrupt
self.class.say_status(nil, nil, header: false)
end
end
|