Class: Gunter::Model::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/gunter/model/template.rb

Overview

Gunter Templates class

Constant Summary collapse

GUNTER_TEMPLATES =
"#{Gunter.root_dir}/templates.yml"

Class Method Summary collapse

Class Method Details

.add(repo, name = nil) ⇒ Hash

Add a new template

Parameters:

  • repo (String)
  • name (String) (defaults to: nil)

    (optional)

Returns:

  • (Hash)

    template created



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

.allHash

Get all templates

Returns:

  • (Hash)

    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

Parameters:

  • term (String) (defaults to: '')

Returns:

  • (Hash)

    templates



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