Class: Trevl::TemplateStore
- Inherits:
-
Object
- Object
- Trevl::TemplateStore
- Defined in:
- lib/trevl/template_store.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #find(name) ⇒ Object
-
#initialize ⇒ TemplateStore
constructor
A new instance of TemplateStore.
- #load_file(path) ⇒ Object
- #load_yaml(yaml_string) ⇒ Object
- #names ⇒ Object
- #register(name, template_hash) ⇒ Object
Constructor Details
#initialize ⇒ TemplateStore
Returns a new instance of TemplateStore.
5 6 7 |
# File 'lib/trevl/template_store.rb', line 5 def initialize @templates = {} end |
Instance Method Details
#clear ⇒ Object
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 |
#names ⇒ Object
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 |