class SocialAvatarProxy::Configuration::FileCache
Public Instance Methods
read(options = {})
click to toggle source
# 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 = {})
click to toggle source
# 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
Private Instance Methods
directory(value)
click to toggle source
set the directory
# File lib/social_avatar_proxy/configuration/file_cache.rb, line 41 def directory(value) @directory = value end
generate_key(options = {})
click to toggle source
# File lib/social_avatar_proxy/configuration/file_cache.rb, line 33 def generate_key(options = {}) # generate a hash for the filename hash = "#{options[:service]}-#{options[:identifier]}" name = "sap-#{Digest::MD5.hexdigest(hash)}" File.join(@directory, name) end