Class: Gunter::Model::Template
- Inherits:
-
Object
- Object
- Gunter::Model::Template
- Defined in:
- lib/gunter/model/template.rb
Overview
Gunter Templates class
Constant Summary collapse
Class Method Summary collapse
-
.add(repo, name = nil) ⇒ Hash
Add a new template.
-
.all ⇒ Hash
Get all templates.
-
.filter(term = '') ⇒ Hash
Filter templates by name or repo.
Class Method Details
.add(repo, name = nil) ⇒ Hash
Add a new template
40 41 42 43 44 45 46 47 48 |
# File 'lib/gunter/model/template.rb', line 40 def add(repo, name = nil) templates = all name ||= File.basename(repo, '.git').split('/').last templates[name] = { repo: repo, name: name, created_at: Time.now } update_templates(templates) templates[name] end |
.all ⇒ Hash
Get all templates
19 20 21 22 23 24 25 |
# File 'lib/gunter/model/template.rb', line 19 def all return YAML.unsafe_load(File.read(GUNTER_TEMPLATES)) if template_file? ensure_gunter_dir! {} end |
.filter(term = '') ⇒ Hash
Filter templates by name or repo
31 32 33 |
# File 'lib/gunter/model/template.rb', line 31 def filter(term = '') all.filter { |name, value| name.include?(term) || value[:repo].include?(term) } end |