Class: Imagecache::Backend::Filesystem

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

Instance Method Summary collapse

Constructor Details

#initialize(root = nil) ⇒ Filesystem

Returns a new instance of Filesystem.



9
10
11
# File 'lib/imagecache/backend/filesystem.rb', line 9

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

Instance Method Details

#delete(key) ⇒ Object



23
24
25
26
27
# File 'lib/imagecache/backend/filesystem.rb', line 23

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

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/imagecache/backend/filesystem.rb', line 29

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

#get(key) ⇒ Object



13
14
15
# File 'lib/imagecache/backend/filesystem.rb', line 13

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

#set(key, value) ⇒ Object



17
18
19
20
21
# File 'lib/imagecache/backend/filesystem.rb', line 17

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