Class: Keynote::Inline::Cache
- Inherits:
-
Object
- Object
- Keynote::Inline::Cache
- Defined in:
- lib/keynote/inline.rb
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(source_file, line, source, format, locals) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
143 144 145 |
# File 'lib/keynote/inline.rb', line 143 def initialize @cache = {} end |
Class Method Details
.fetch(source_file, line, source, format, locals) ⇒ Object
134 135 136 137 |
# File 'lib/keynote/inline.rb', line 134 def self.fetch(source_file, line, source, format, locals) instance = (Thread.current[:_keynote_template_cache] ||= Cache.new) instance.fetch(source_file, line, source, format, locals) end |
.reset ⇒ Object
139 140 141 |
# File 'lib/keynote/inline.rb', line 139 def self.reset Thread.current[:_keynote_template_cache] = nil end |
Instance Method Details
#fetch(source_file, line, source, format, locals) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/keynote/inline.rb', line 147 def fetch(source_file, line, source, format, locals) local_names = locals.keys.sort cache_key = ["#{source_file}:#{line}", *local_names].freeze new_mtime = File.mtime(source_file).to_f template, mtime = @cache[cache_key] if new_mtime != mtime source = unindent(source.chomp) template = Template.new(source, cache_key[0], handler_for_format(format), format:, locals: local_names) @cache[cache_key] = [template, new_mtime] end template end |