summaryrefslogtreecommitdiff
path: root/app/finders/template_finder.rb
blob: 7cdc7a32acce50e9e2b657a9f12acd61b39108f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class TemplateFinder
  VENDORED_TEMPLATES = {
    dockerfiles: ::Gitlab::Template::DockerfileTemplate,
    gitignores: ::Gitlab::Template::GitignoreTemplate,
    gitlab_ci_ymls: ::Gitlab::Template::GitlabCiYmlTemplate
  }.freeze

  class << self
    def build(type, params = {})
      if type == :licenses
        LicenseTemplateFinder.new(params) # rubocop: disable CodeReuse/Finder
      else
        new(type, params)
      end
    end
  end

  attr_reader :type, :params

  attr_reader :vendored_templates
  private :vendored_templates

  def initialize(type, params = {})
    @type = type
    @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