Module: TemplateRenderer::ClassMethods

Defined in:
lib/generators/template_renderer.rb

Overview

Class methods added to the including class

Instance Method Summary collapse

Instance Method Details

#clear_template_cacheObject

Clear the template cache (useful for testing) Clears cache for this class and all subclasses



81
82
83
84
85
86
87
# File 'lib/generators/template_renderer.rb', line 81

def clear_template_cache
  @template_renderer&.clear
  @template_renderer = nil
  subclasses.each do |subclass|
    subclass.clear_template_cache if subclass.respond_to?(:clear_template_cache)
  end
end

#template_cache_statsObject

Get cache statistics (useful for debugging) Aggregates stats across this class and all subclasses



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/generators/template_renderer.rb', line 91

def template_cache_stats
  own = @template_renderer&.stats || { size: 0, entries: [], memory_estimate: 0 }
  subclasses.each do |subclass|
    next unless subclass.respond_to?(:template_cache_stats)

    sub_stats = subclass.instance_variable_get(:@template_renderer)&.stats
    next unless sub_stats

    own[:size] += sub_stats[:size]
    own[:entries].concat(sub_stats[:entries])
    own[:memory_estimate] += sub_stats[:memory_estimate]
  end
  own
end

#template_rendererObject

Get the shared template renderer instance Each generator class gets its own cache instance



75
76
77
# File 'lib/generators/template_renderer.rb', line 75

def template_renderer
  @template_renderer ||= PartialCache.new(self)
end