Class: Metanorma::Release::FileCacheStore
- Inherits:
-
Object
- Object
- Metanorma::Release::FileCacheStore
- Includes:
- CacheStore
- Defined in:
- lib/metanorma/release/cache_store.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(directory) ⇒ FileCacheStore
constructor
A new instance of FileCacheStore.
- #keys ⇒ Object
- #set(key, value) ⇒ Object
Constructor Details
#initialize(directory) ⇒ FileCacheStore
Returns a new instance of FileCacheStore.
32 33 34 |
# File 'lib/metanorma/release/cache_store.rb', line 32 def initialize(directory) @directory = directory end |
Instance Method Details
#clear ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/metanorma/release/cache_store.rb', line 53 def clear return unless Dir.exist?(@directory) Dir.glob(File.join(@directory, '*')).each do |f| File.delete(f) if File.file?(f) end end |
#delete(key) ⇒ Object
48 49 50 51 |
# File 'lib/metanorma/release/cache_store.rb', line 48 def delete(key) path = file_path(key) File.delete(path) if File.exist?(path) end |
#get(key) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/metanorma/release/cache_store.rb', line 36 def get(key) path = file_path(key) return nil unless File.exist?(path) File.read(path) end |
#keys ⇒ Object
61 62 63 64 65 66 |
# File 'lib/metanorma/release/cache_store.rb', line 61 def keys return [] unless Dir.exist?(@directory) Dir.glob(File.join(@directory, '*')).select { |f| File.file?(f) } .map { |f| File.basename(f) } end |
#set(key, value) ⇒ Object
43 44 45 46 |
# File 'lib/metanorma/release/cache_store.rb', line 43 def set(key, value) FileUtils.mkdir_p(@directory) File.write(file_path(key), value) end |