Class: Puma::Acme::DiskStore
- Inherits:
-
Object
- Object
- Puma::Acme::DiskStore
- Defined in:
- lib/puma/acme/disk_store.rb
Overview
DiskStore is a simple key/value store that persists to disk using PStore.
Instance Method Summary collapse
- #delete(key, _options = nil) ⇒ Object
- #fetch(key, _options = nil, &block) ⇒ Object
-
#initialize(dir) ⇒ DiskStore
constructor
A new instance of DiskStore.
- #read(key, _options = nil) ⇒ Object
- #write(key, value, _options = nil) ⇒ Object
Constructor Details
#initialize(dir) ⇒ DiskStore
Returns a new instance of DiskStore.
7 8 9 10 |
# File 'lib/puma/acme/disk_store.rb', line 7 def initialize(dir) path = File.join(dir, 'puma-acme.pstore') @pstore = PStore.new(path, true) end |
Instance Method Details
#delete(key, _options = nil) ⇒ Object
12 13 14 15 16 |
# File 'lib/puma/acme/disk_store.rb', line 12 def delete(key, = nil) @pstore.transaction do !!@pstore.delete(key) end end |
#fetch(key, _options = nil, &block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/puma/acme/disk_store.rb', line 18 def fetch(key, = nil, &block) raise ArgumentError if block.nil? @pstore.transaction do @pstore[key] || (@pstore[key] = yield(key)) end end |
#read(key, _options = nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/puma/acme/disk_store.rb', line 26 def read(key, = nil) @pstore.transaction(true) do @pstore[key] end end |
#write(key, value, _options = nil) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/puma/acme/disk_store.rb', line 32 def write(key, value, = nil) @pstore.transaction do @pstore[key] = value true end end |