Module: Paperclip::Storage::Redis

Defined in:
lib/paperclip/storage/redis.rb

Defined Under Namespace

Classes: App

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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

Instance Method Details

#copy_to_local_file(style, destination_path) ⇒ Object



42
43
44
45
46
# File 'lib/paperclip/storage/redis.rb', line 42

def copy_to_local_file(style, destination_path)
	File.open(destination_path, "w") do |f|
		f << read
	end
end

#exists?(style = default_style) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/paperclip/storage/redis.rb', line 19

def exists?(style = default_style)
	@redis.exists(path(style))
end

#flush_deletesObject



35
36
37
38
39
40
# File 'lib/paperclip/storage/redis.rb', line 35

def flush_deletes
	@queued_for_delete.each do |path|
		log("deleting #{path}")
		@redis.del(path)
	end
end

#flush_writesObject



27
28
29
30
31
32
33
# File 'lib/paperclip/storage/redis.rb', line 27

def flush_writes
	@queued_for_write.each do |style, file|
		log("saving #{path(style)}")
		file.rewind
		@redis.set(path(style), file.read)
	end
end

#pingObject



23
24
25
# File 'lib/paperclip/storage/redis.rb', line 23

def ping
	@redis.ping
end

#read(style = default_style) ⇒ Object



48
49
50
# File 'lib/paperclip/storage/redis.rb', line 48

def read(style = default_style)
	@redis.get(path(style))
end