Class: Kadim::MemoryResolver::TemplateStore
- Inherits:
-
Object
- Object
- Kadim::MemoryResolver::TemplateStore
- Defined in:
- lib/kadim/template/memory_resolver.rb
Constant Summary collapse
- SmallCache =
ActionView::Resolver::Cache::SmallCache
- PARTIAL_BLOCK =
->(store, partial) { store[partial] = SmallCache.new }
- PREFIX_BLOCK =
->(store, prefix) { store[prefix] = SmallCache.new(&PARTIAL_BLOCK) }
- NAME_BLOCK =
->(store, name) { store[name] = SmallCache.new(&PREFIX_BLOCK) }
- NO_TEMPLATES =
usually a majority of template look ups return nothing, use this canonical preallocated array to save memory
[].freeze
Instance Method Summary collapse
- #add(body, path, partial) ⇒ Object
- #clear ⇒ Object
- #find(name, prefix, partial) ⇒ Object
-
#initialize ⇒ TemplateStore
constructor
A new instance of TemplateStore.
Constructor Details
#initialize ⇒ TemplateStore
Returns a new instance of TemplateStore.
19 20 21 |
# File 'lib/kadim/template/memory_resolver.rb', line 19 def initialize @data = SmallCache.new(&NAME_BLOCK) end |
Instance Method Details
#add(body, path, partial) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/kadim/template/memory_resolver.rb', line 27 def add(body, path, partial) name = path.split("/").last name = name[1..-1] if partial prefix = path.split("/")[0..-2].join("/") @data[name][prefix][partial] = body end |
#clear ⇒ Object
34 35 36 |
# File 'lib/kadim/template/memory_resolver.rb', line 34 def clear @data.clear end |
#find(name, prefix, partial) ⇒ Object
23 24 25 |
# File 'lib/kadim/template/memory_resolver.rb', line 23 def find(name, prefix, partial) @data[name][prefix][partial].presence || NO_TEMPLATES end |