Class: TemplateFinder
- Inherits:
-
Object
- Object
- TemplateFinder
- 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, issues: ::Gitlab::Template::IssueTemplate, merge_requests: ::Gitlab::Template::MergeRequestTemplate ).freeze
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .all_template_names(project, type) ⇒ Object
- .build(type, project, params = {}) ⇒ Object
- .type_allowed?(type) ⇒ Boolean
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(type, project, params = {}) ⇒ TemplateFinder
constructor
A new instance of TemplateFinder.
- #template_names ⇒ Object
Constructor Details
#initialize(type, project, params = {}) ⇒ TemplateFinder
Returns a new instance of TemplateFinder.
41 42 43 44 45 46 47 |
# File 'app/finders/template_finder.rb', line 41 def initialize(type, project, params = {}) @type = type @project = project @params = params @vendored_templates = VENDORED_TEMPLATES.fetch(type) end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
36 37 38 |
# File 'app/finders/template_finder.rb', line 36 def params @params end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
36 37 38 |
# File 'app/finders/template_finder.rb', line 36 def project @project end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
36 37 38 |
# File 'app/finders/template_finder.rb', line 36 def type @type end |
Class Method Details
.all_template_names(project, type) ⇒ Object
23 24 25 26 27 |
# File 'app/finders/template_finder.rb', line 23 def all_template_names(project, type) return {} unless type_allowed?(type) build(type, project).template_names end |
.build(type, project, params = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'app/finders/template_finder.rb', line 15 def build(type, project, params = {}) if type.to_s == 'licenses' LicenseTemplateFinder.new(project, params) # rubocop: disable CodeReuse/Finder elsif type_allowed?(type) new(type, project, params) end end |
.type_allowed?(type) ⇒ Boolean
29 30 31 32 33 |
# File 'app/finders/template_finder.rb', line 29 def type_allowed?(type) return true if type.to_s == 'licenses' VENDORED_TEMPLATES.key?(type) end |
Instance Method Details
#execute ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/finders/template_finder.rb', line 49 def execute if params[:name] vendored_templates.find(params[:name], project) else vendored_templates.all(project) end end |
#template_names ⇒ Object
57 58 59 |
# File 'app/finders/template_finder.rb', line 57 def template_names vendored_templates.template_names(project) end |