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
|
# File 'lib/kube_deploy_tools/file_filter.rb', line 8
def self.filter_files(filters:, files_path:)
all_files = Dir[File.join(files_path, '**', '*')].to_set
filtered_files = if filters.any? { |k, _| k =~ /include_/ }
Set.new
else
Set.new(all_files)
end
filters.each do |action, globpath|
if action =~ /_dir$/
globpath = File.join(files_path, globpath.gsub(/^[\/*]+|[\/*]+$/, ""), '**', '*')
end
case action
when /^include_(files|dir)$/
filtered_files.merge( all_files.select{ |f| File.fnmatch?(globpath, f, File::FNM_PATHNAME) } )
when /^exclude_(files|dir)$/
filtered_files.reject!{ |f| File.fnmatch?(globpath, f, File::FNM_PATHNAME) }
else
raise "you want to #{action}: wat do"
end
end
Logger.debug("\nYour filter generates following paths: \n#{filtered_files.to_a.join("\n")}")
filtered_files
end
|