Class: Trevl::TemplateStore

Inherits:
Object
  • Object
show all
Defined in:
lib/trevl/template_store.rb

Instance Method Summary collapse

Constructor Details

#initializeTemplateStore

Returns a new instance of TemplateStore.



5
6
7
# File 'lib/trevl/template_store.rb', line 5

def initialize
  @templates = {}
end

Instance Method Details

#clearObject



34
35
36
# File 'lib/trevl/template_store.rb', line 34

def clear
  @templates.clear
end

#find(name) ⇒ Object



13
14
15
# File 'lib/trevl/template_store.rb', line 13

def find(name)
  @templates[name.to_s.downcase]
end

#load_file(path) ⇒ Object



26
27
28
# File 'lib/trevl/template_store.rb', line 26

def load_file(path)
  load_yaml(File.read(path))
end

#load_yaml(yaml_string) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/trevl/template_store.rb', line 17

def load_yaml(yaml_string)
  data = YAML.safe_load(yaml_string, permitted_classes: [Hash], aliases: true)
  return unless data.is_a?(Hash)

  data.each do |name, template_hash|
    register(name, template_hash) if template_hash.is_a?(Hash)
  end
end

#namesObject



30
31
32
# File 'lib/trevl/template_store.rb', line 30

def names
  @templates.keys
end

#register(name, template_hash) ⇒ Object



9
10
11
# File 'lib/trevl/template_store.rb', line 9

def register(name, template_hash)
  @templates[name.to_s.downcase] = template_hash
end