Class: OsCtld::ErbTemplateCache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/osctld/erb_template_cache.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeErbTemplateCache

Returns a new instance of ErbTemplateCache.



14
15
16
17
# File 'lib/osctld/erb_template_cache.rb', line 14

def initialize
  @templates = {}
  load
end

Instance Attribute Details

#templatesObject (readonly, protected)

Returns the value of attribute templates.



36
37
38
# File 'lib/osctld/erb_template_cache.rb', line 36

def templates
  @templates
end

Class Method Details

.[](name) ⇒ Object



7
8
9
# File 'lib/osctld/erb_template_cache.rb', line 7

def [](name)
  instance[name]
end

Instance Method Details

#[](name) ⇒ ERB

Parameters:

  • name (String)

Returns:

  • (ERB)


30
31
32
# File 'lib/osctld/erb_template_cache.rb', line 30

def [](name)
  templates[name].clone
end

#loadObject



19
20
21
22
23
24
25
26
# File 'lib/osctld/erb_template_cache.rb', line 19

def load
  templates.clear

  Dir.glob('**/*.erb', base: OsCtld.template_dir).each do |tpl|
    content = File.read(File.join(OsCtld.template_dir, tpl))
    templates[tpl[0..-5]] = ERB.new(content, trim_mode: '-')
  end
end