Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <zegerjan@gitlab.com>2016-06-02 19:20:08 +0300
committerAlfredo Sumaran <alfredo@gitlab.com>2016-06-20 22:48:28 +0300
commit620d014aefd23030ed6ae043e223ccc5dc52fc8a (patch)
tree9324f2cbb23bdcc4f02d9b29b349894e4b43ac8c /lib/gitlab/template/base_template.rb
parent567f6a7b4271d97afd6dea1545210b9aba858421 (diff)
Implement backend gitlab ci dropdown
This commit builds on the groundwork in ee008e300b1ec0abcc90e6a30816ec0754cea0dd, which refactored the backend so the same code could be used for new dropdowns. In this commit its used for templates for the `.gitlab-ci.yml` files.
Diffstat (limited to 'lib/gitlab/template/base_template.rb')
-rw-r--r--lib/gitlab/template/base_template.rb35
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/gitlab/template/base_template.rb b/lib/gitlab/template/base_template.rb
index e1cdfc8f5f6..652a496b57b 100644
--- a/lib/gitlab/template/base_template.rb
+++ b/lib/gitlab/template/base_template.rb
@@ -13,40 +13,53 @@ module Gitlab
File.read(@path)
end
+ def categories
+ raise NotImplementedError
+ end
+
+ def extension
+ raise NotImplementedError
+ end
+
+ def base_dir
+ raise NotImplementedError
+ end
+
class << self
def all
- self.category_directories.flat_map do |dir|
- templates_for_folder(dir)
- end
+ self.categories.keys.flat_map { |cat| by_category(cat) }
end
def find(key)
file_name = "#{key}#{self.extension}"
directory = select_directory(file_name)
- directory ? new(File.join(directory, file_name)) : nil
+ directory ? new(File.join(category_directory(directory), file_name)) : nil
end
def by_category(category)
- templates_for_folder(categories[category])
+ templates_for_directory(category_directory(category))
end
- def category_directories
- self.categories.values.map { |subdir| File.join(base_dir, subdir)}
+ def category_directory(category)
+ File.join(base_dir, categories[category])
end
private
def select_directory(file_name)
- category_directories.find { |dir| File.exist?(File.join(dir, file_name)) }
+ categories.keys.find do |category|
+ File.exist?(File.join(category_directory(category), file_name))
+ end
end
- def templates_for_folder(dir)
- Dir.glob("#{dir.to_s}/*#{self.extension}").select { |f| f =~ filter_regex }.map { |f| new(f) }
+ def templates_for_directory(dir)
+ dir << '/' unless dir.end_with?('/')
+ Dir.glob(File.join(dir, "*#{self.extension}")).select { |f| f =~ filter_regex }.map { |f| new(f) }
end
def filter_regex
- /#{Regexp.escape(extension)}\z/
+ @filter_reges ||= /#{Regexp.escape(extension)}\z/
end
end
end