Class: LicenseTemplateFinder

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

Overview

LicenseTemplateFinder

Used to find license templates, which may come from a variety of external sources

Params can be any of the following:

popular: boolean. When set to true, only "popular" licenses are shown. When
         false, all licenses except popular ones are shown. When nil (the
         default), *all* licenses will be shown.
name:    string. If set, return a single license matching that name (or nil)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, params = {}) ⇒ LicenseTemplateFinder

Returns a new instance of LicenseTemplateFinder.



18
19
20
21
# File 'app/finders/license_template_finder.rb', line 18

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

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



16
17
18
# File 'app/finders/license_template_finder.rb', line 16

def params
  @params
end

#projectObject (readonly)

Returns the value of attribute project.



16
17
18
# File 'app/finders/license_template_finder.rb', line 16

def project
  @project
end

Instance Method Details

#executeObject



23
24
25
26
27
28
29
# File 'app/finders/license_template_finder.rb', line 23

def execute
  if params[:name]
    vendored_licenses.find { |template| template.key == params[:name] }
  else
    vendored_licenses
  end
end

#template_namesObject



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

def template_names
  ::Gitlab::Template::BaseTemplate.template_names_by_category(vendored_licenses)
end