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.
33 34 35 |
# File 'lib/metanorma/release/cache_store.rb', line 33 def initialize(directory) @directory = directory end |
Instance Method Details
#clear ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/metanorma/release/cache_store.rb', line 54 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
49 50 51 52 |
# File 'lib/metanorma/release/cache_store.rb', line 49 def delete(key) path = file_path(key) FileUtils.rm_f(path) end |
#get(key) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/metanorma/release/cache_store.rb', line 37 def get(key) path = file_path(key) return nil unless File.exist?(path) File.read(path) end |
#keys ⇒ Object
62 63 64 65 66 67 |
# File 'lib/metanorma/release/cache_store.rb', line 62 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
44 45 46 47 |
# File 'lib/metanorma/release/cache_store.rb', line 44 def set(key, value) FileUtils.mkdir_p(@directory) File.write(file_path(key), value) end |