module Paperclip::Storage::Redis

Public Class Methods

extended(base) click to toggle source
# File lib/paperclip/storage/redis.rb, line 4
def self.extended(base)
        begin
                require 'redis'
        rescue LoadError => e
                e.message << " (You may need to install the redis gem)"
                raise e
        end unless defined?(Redis)

        base.instance_eval do
                @options[:path] ||= ":class/:attachment/:id_partition/:style/:filename"
                @options[:url] ||= "/dynamic/:class/:attachment/:id_partition/:style/:filename"
                @redis = ::Redis.new( url: ENV['PAPERCLIP_REDIS'])
        end
end

Public Instance Methods

copy_to_local_file(style, destination_path) click to toggle source
# File lib/paperclip/storage/redis.rb, line 48
def copy_to_local_file(style, destination_path)
        File.open(destination_path, "w") do |f|
                f << read
        end
end
exists?(style = default_style) click to toggle source
# File lib/paperclip/storage/redis.rb, line 19
def exists?(style = default_style)
        @redis.with_reconnect do
                @redis.exists(path(style))
        end
end
flush_deletes() click to toggle source
# File lib/paperclip/storage/redis.rb, line 39
def flush_deletes
        @queued_for_delete.each do |path|
                log("deleting #{path}")
                @redis.with_reconnect do
                        @redis.del(path)
                end
        end
end
flush_writes() click to toggle source
# File lib/paperclip/storage/redis.rb, line 29
def flush_writes
        @queued_for_write.each do |style, file|
                log("saving #{path(style)}")
                file.rewind
                @redis.with_reconnect do
                        @redis.set(path(style), file.read)
                end
        end
end
ping() click to toggle source
# File lib/paperclip/storage/redis.rb, line 25
def ping
        @redis.ping
end
read(style = default_style) click to toggle source
# File lib/paperclip/storage/redis.rb, line 54
def read(style = default_style)
        @redis.with_reconnect do
                @redis.get(path(style))
        end
end