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)

Constant Summary collapse

EXCLUDED_LICENSES =
%w[wtfpl].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LicenseTemplateFinder.



20
21
22
23
# File 'app/finders/license_template_finder.rb', line 20

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

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#projectObject (readonly)

Returns the value of attribute project.



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

def project
  @project
end

Instance Method Details

#executeObject



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

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

#template_namesObject



33
34
35
# File 'app/finders/license_template_finder.rb', line 33

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