Class: Imagecache::Backends::Filesystem

Inherits:
Object
  • Object
show all
Defined in:
lib/imagecache/backends/filesystem.rb

Instance Method Summary collapse

Constructor Details

#initialize(root = nil) ⇒ Filesystem

Returns a new instance of Filesystem.



7
8
9
# File 'lib/imagecache/backends/filesystem.rb', line 7

def initialize(root = nil)
  @root = root || "#{Rails.root}/public"
end

Instance Method Details

#delete(key) ⇒ Object



21
22
23
24
25
# File 'lib/imagecache/backends/filesystem.rb', line 21

def delete(key)
  keypath = path(key)
  File.unlink(keypath)
  rmdir(keypath)
end

#exists?(key) ⇒ Boolean

Returns:



27
28
29
# File 'lib/imagecache/backends/filesystem.rb', line 27

def exists?(key)
  File.exist?(path(key))
end

#get(key) ⇒ Object



11
12
13
# File 'lib/imagecache/backends/filesystem.rb', line 11

def get(key)
  File.open(path(key)).read
end

#set(key, value) ⇒ Object



15
16
17
18
19
# File 'lib/imagecache/backends/filesystem.rb', line 15

def set(key, value)
  keypath = path(key)
  mkdir(keypath)
  File.open(keypath, 'wb') { |file| file.write(value) }
end