debian-mirror-gitlab/app/finders/template_finder.rb

45 lines
1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-11-20 20:47:30 +05:30
class TemplateFinder
2018-12-05 23:21:45 +05:30
include Gitlab::Utils::StrongMemoize
VENDORED_TEMPLATES = HashWithIndifferentAccess.new(
2018-11-20 20:47:30 +05:30
dockerfiles: ::Gitlab::Template::DockerfileTemplate,
gitignores: ::Gitlab::Template::GitignoreTemplate,
gitlab_ci_ymls: ::Gitlab::Template::GitlabCiYmlTemplate
2018-12-05 23:21:45 +05:30
).freeze
2018-11-20 20:47:30 +05:30
class << self
2018-12-05 23:21:45 +05:30
def build(type, project, params = {})
if type.to_s == 'licenses'
LicenseTemplateFinder.new(project, params) # rubocop: disable CodeReuse/Finder
2018-11-20 20:47:30 +05:30
else
2018-12-05 23:21:45 +05:30
new(type, project, params)
2018-11-20 20:47:30 +05:30
end
end
end
2018-12-05 23:21:45 +05:30
attr_reader :type, :project, :params
2018-11-20 20:47:30 +05:30
attr_reader :vendored_templates
private :vendored_templates
2018-12-05 23:21:45 +05:30
def initialize(type, project, params = {})
2018-11-20 20:47:30 +05:30
@type = type
2018-12-05 23:21:45 +05:30
@project = project
2018-11-20 20:47:30 +05:30
@params = params
@vendored_templates = VENDORED_TEMPLATES.fetch(type)
end
def execute
if params[:name]
vendored_templates.find(params[:name])
else
vendored_templates.all
end
end
end
2020-04-22 19:07:51 +05:30
TemplateFinder.prepend_if_ee('::EE::TemplateFinder')