2018-09-11 15:08:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-28 09:14:39 -04:00
|
|
|
class TemplateFinder
|
2018-10-02 19:00:38 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2019-09-13 09:26:31 -04:00
|
|
|
prepend_if_ee('::EE::TemplateFinder') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
VENDORED_TEMPLATES = HashWithIndifferentAccess.new(
|
2018-08-28 09:14:39 -04:00
|
|
|
dockerfiles: ::Gitlab::Template::DockerfileTemplate,
|
|
|
|
gitignores: ::Gitlab::Template::GitignoreTemplate,
|
|
|
|
gitlab_ci_ymls: ::Gitlab::Template::GitlabCiYmlTemplate
|
2018-10-02 19:00:38 -04:00
|
|
|
).freeze
|
2018-08-28 09:14:39 -04:00
|
|
|
|
2018-09-05 09:45:02 -04:00
|
|
|
class << self
|
2018-10-02 19:00:38 -04:00
|
|
|
def build(type, project, params = {})
|
|
|
|
if type.to_s == 'licenses'
|
|
|
|
LicenseTemplateFinder.new(project, params) # rubocop: disable CodeReuse/Finder
|
2018-09-05 09:45:02 -04:00
|
|
|
else
|
2018-10-02 19:00:38 -04:00
|
|
|
new(type, project, params)
|
2018-09-05 09:45:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
attr_reader :type, :project, :params
|
2018-08-28 09:14:39 -04:00
|
|
|
|
|
|
|
attr_reader :vendored_templates
|
|
|
|
private :vendored_templates
|
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
def initialize(type, project, params = {})
|
2018-08-28 09:14:39 -04:00
|
|
|
@type = type
|
2018-10-02 19:00:38 -04:00
|
|
|
@project = project
|
2018-08-28 09:14:39 -04:00
|
|
|
@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
|