Class: TemplateFinder

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/finders/template_finder.rb

Constant Summary collapse

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
).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(type, project, params = {}) ⇒ TemplateFinder

Returns a new instance of TemplateFinder.


30
31
32
33
34
35
36
# File 'app/finders/template_finder.rb', line 30

def initialize(type, project, params = {})
  @type = type
  @project = project
  @params = params

  @vendored_templates = VENDORED_TEMPLATES.fetch(type)
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params


25
26
27
# File 'app/finders/template_finder.rb', line 25

def params
  @params
end

#projectObject (readonly)

Returns the value of attribute project


25
26
27
# File 'app/finders/template_finder.rb', line 25

def project
  @project
end

#typeObject (readonly)

Returns the value of attribute type


25
26
27
# File 'app/finders/template_finder.rb', line 25

def type
  @type
end

Class Method Details

.build(type, project, params = {}) ⇒ Object


16
17
18
19
20
21
22
# File 'app/finders/template_finder.rb', line 16

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

Instance Method Details

#executeObject


38
39
40
41
42
43
44
# File 'app/finders/template_finder.rb', line 38

def execute
  if params[:name]
    vendored_templates.find(params[:name], project)
  else
    vendored_templates.all(project)
  end
end