Class: Imagecache::Backends::Filesystem
- Inherits:
-
Object
- Object
- Imagecache::Backends::Filesystem
- Defined in:
- lib/imagecache/backends/filesystem.rb
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #exists?(key) ⇒ Boolean
- #get(key) ⇒ Object
-
#initialize(root = nil) ⇒ Filesystem
constructor
A new instance of Filesystem.
- #set(key, value) ⇒ Object
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
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 |