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

48 lines
1.2 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,
2020-10-24 23:57:45 +05:30
gitlab_ci_ymls: ::Gitlab::Template::GitlabCiYmlTemplate,
metrics_dashboard_ymls: ::Gitlab::Template::MetricsDashboardTemplate,
issues: ::Gitlab::Template::IssueTemplate,
merge_requests: ::Gitlab::Template::MergeRequestTemplate
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]
2020-10-24 23:57:45 +05:30
vendored_templates.find(params[:name], project)
2018-11-20 20:47:30 +05:30
else
2020-10-24 23:57:45 +05:30
vendored_templates.all(project)
2018-11-20 20:47:30 +05:30
end
end
end
2020-04-22 19:07:51 +05:30
TemplateFinder.prepend_if_ee('::EE::TemplateFinder')