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.


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

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.


31
32
33
# File 'app/finders/template_finder.rb', line 31

def params
  @params
end

#projectObject (readonly)

Returns the value of attribute project.


31
32
33
# File 'app/finders/template_finder.rb', line 31

def project
  @project
end

#typeObject (readonly)

Returns the value of attribute type.


31
32
33
# File 'app/finders/template_finder.rb', line 31

def type
  @type
end

Class Method Details

.all_template_names(project, type) ⇒ Object


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

def all_template_names(project, type)
  return {} if !VENDORED_TEMPLATES.key?(type.to_s) && type.to_s != 'licenses'

  build(type, project).template_names
end

.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


44
45
46
47
48
49
50
# File 'app/finders/template_finder.rb', line 44

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

#template_namesObject


52
53
54
# File 'app/finders/template_finder.rb', line 52

def template_names
  vendored_templates.template_names(project)
end