Class: Shellfie::RenderChromeCache

Inherits:
Object
  • Object
show all
Defined in:
lib/shellfie/render_chrome_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeRenderChromeCache

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

#cleanupObject



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

Yields:

  • (temp.path)


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