Class: SocialAvatarProxy::Configuration::FileCache

Inherits:
Cache
  • Object
show all
Defined in:
lib/social_avatar_proxy/configuration/file_cache.rb

Instance Method Summary collapse

Methods inherited from Cache

#configure, #disabled?, #enabled?, #fetch

Instance Method Details

#read(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/social_avatar_proxy/configuration/file_cache.rb', line 9

def read(options = {})
  path = generate_key(options)
  # ensure the file exists and it's readable
  unless File.exist?(path) && File.readable?(path)
    return false
  end
  # return the file
  AvatarFile.new(path).tap do |file|
    file.mtime(File.mtime(path))
  end
end

#write(file, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/social_avatar_proxy/configuration/file_cache.rb', line 21

def write(file, options = {})
  # generate the file location
  path = generate_key(options)
  # create the folder
  FileUtils.mkdir_p File.dirname(path)
  # write the file
  File.open(path, "wb") do |f|
    f.write(file.read)
  end
end