Class: Gitlab::Template::Finders::GlobalTemplateFinder
Instance Method Summary
collapse
#category_directory, filter_regex
Constructor Details
#initialize(base_dir, extension, categories = {}, include_categories_for_file = {}, excluded_patterns: []) ⇒ GlobalTemplateFinder
Returns a new instance of GlobalTemplateFinder.
8
9
10
11
12
13
14
15
|
# File 'lib/gitlab/template/finders/global_template_finder.rb', line 8
def initialize(base_dir, extension, categories = {}, include_categories_for_file = {}, excluded_patterns: [])
@categories = categories
@extension = extension
@include_categories_for_file = include_categories_for_file
@excluded_patterns = excluded_patterns
super(base_dir)
end
|
Instance Method Details
#find(key) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/gitlab/template/finders/global_template_finder.rb', line 21
def find(key)
return if excluded?(key)
file_name = "#{key}#{@extension}"
Gitlab::PathTraversal.check_path_traversal!(file_name)
directory = select_directory(file_name)
directory ? File.join(category_directory(directory), file_name) : nil
end
|
#list_files_for(dir) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/gitlab/template/finders/global_template_finder.rb', line 34
def list_files_for(dir)
dir = "#{dir}/" unless dir.end_with?('/')
Dir.glob(File.join(dir, "*#{@extension}")).select do |f|
next if excluded?(f)
f =~ self.class.filter_regex(@extension)
end
end
|
#read(path) ⇒ Object
17
18
19
|
# File 'lib/gitlab/template/finders/global_template_finder.rb', line 17
def read(path)
File.read(path)
end
|