Class: Shellfie::RenderChromeCache
- Inherits:
-
Object
- Object
- Shellfie::RenderChromeCache
- Defined in:
- lib/shellfie/render_chrome_cache.rb
Instance Method Summary collapse
- #cleanup ⇒ Object
- #fetch(geometry, transparent:) {|temp.path| ... } ⇒ Object
-
#initialize ⇒ RenderChromeCache
constructor
A new instance of RenderChromeCache.
Constructor Details
#initialize ⇒ RenderChromeCache
Returns a new instance of RenderChromeCache.
7 8 9 |
# File 'lib/shellfie/render_chrome_cache.rb', line 7 def initialize @entries = {} end |
Instance Method Details
#cleanup ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/shellfie/render_chrome_cache.rb', line 22 def cleanup @entries.each_value do |temp| File.delete(temp.path) if File.exist?(temp.path) temp.close unless temp.closed? end @entries.clear end |
#fetch(geometry, transparent:) {|temp.path| ... } ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/shellfie/render_chrome_cache.rb', line 11 def fetch(geometry, transparent:) key = cache_key(geometry, transparent) return @entries[key].path if @entries.key?(key) temp = Tempfile.new(["shellfie-chrome", ".png"], binmode: true) temp.close yield temp.path @entries[key] = temp temp.path end |