gitlab-org--gitlab-foss/app/finders/template_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class TemplateFinder
2018-10-02 19:00:38 -04:00
include Gitlab::Utils::StrongMemoize
VENDORED_TEMPLATES = HashWithIndifferentAccess.new(
dockerfiles: ::Gitlab::Template::DockerfileTemplate,
gitignores: ::Gitlab::Template::GitignoreTemplate,
gitlab_ci_ymls: ::Gitlab::Template::GitlabCiYmlTemplate,
metrics_dashboard_ymls: ::Gitlab::Template::MetricsDashboardTemplate,
issues: ::Gitlab::Template::IssueTemplate,
merge_requests: ::Gitlab::Template::MergeRequestTemplate
2018-10-02 19:00:38 -04:00
).freeze
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
else
2018-10-02 19:00:38 -04:00
new(type, project, params)
end
end
def all_template_names(project, type)
return {} if !VENDORED_TEMPLATES.key?(type.to_s) && type.to_s != 'licenses'
build(type, project).template_names
end
end
2018-10-02 19:00:38 -04:00
attr_reader :type, :project, :params
attr_reader :vendored_templates
private :vendored_templates
2018-10-02 19:00:38 -04:00
def initialize(type, project, params = {})
@type = type
2018-10-02 19:00:38 -04:00
@project = project
@params = params
@vendored_templates = VENDORED_TEMPLATES.fetch(type)
end
def execute
if params[:name]
vendored_templates.find(params[:name], project)
else
vendored_templates.all(project)
end
end
def template_names
vendored_templates.template_names(project)
end
end
TemplateFinder.prepend_mod_with('TemplateFinder')