Class: Ruco::FileStore
Instance Method Summary collapse
- #cache(key, &block) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #file(key) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(folder, options = {}) ⇒ FileStore
constructor
A new instance of FileStore.
- #set(key, value) ⇒ Object
Constructor Details
Instance Method Details
#cache(key, &block) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/ruco/file_store.rb', line 23 def cache(key, &block) value = get(key) if value.nil? value = yield set(key, value) end value end |
#clear ⇒ Object
37 38 39 |
# File 'lib/ruco/file_store.rb', line 37 def clear FileUtils.rm_rf(@folder) end |
#delete(key) ⇒ Object
32 33 34 35 |
# File 'lib/ruco/file_store.rb', line 32 def delete(key) FileUtils.rm(file(key)) rescue Errno::ENOENT end |
#file(key) ⇒ Object
41 42 43 |
# File 'lib/ruco/file_store.rb', line 41 def file(key) "#{@folder}/#{Digest::MD5.hexdigest(key)}.yml" end |
#get(key) ⇒ Object
18 19 20 21 |
# File 'lib/ruco/file_store.rb', line 18 def get(key) file = file(key) deserialize File.binary_read(file) if File.exist?(file) end |