Class: Moneta::Adapters::PStore
- Inherits:
-
Base
- Object
- Base
- Moneta::Adapters::PStore
show all
- Defined in:
- lib/moneta/adapters/pstore.rb
Overview
Direct Known Subclasses
YAML
Instance Method Summary
collapse
Methods inherited from Base
#[], #[]=, #close, #decrement, #fetch
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ PStore
12
13
14
15
16
|
# File 'lib/moneta/adapters/pstore.rb', line 12
def initialize(options = {})
raise ArgumentError, 'Option :file is required' unless options[:file]
FileUtils.mkpath(::File.dirname(options[:file]))
@pstore = new_store(options)
end
|
Instance Method Details
#clear(options = {}) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/moneta/adapters/pstore.rb', line 45
def clear(options = {})
@pstore.transaction do
@pstore.roots.each do |key|
@pstore.delete(key)
end
end
self
end
|
#delete(key, options = {}) ⇒ Object
30
31
32
|
# File 'lib/moneta/adapters/pstore.rb', line 30
def delete(key, options = {})
@pstore.transaction { @pstore.delete(key) }
end
|
#increment(key, amount = 1, options = {}) ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/moneta/adapters/pstore.rb', line 34
def increment(key, amount = 1, options = {})
@pstore.transaction do
value = @pstore[key]
intvalue = value.to_i
raise 'Tried to increment non integer value' unless value == nil || intvalue.to_s == value.to_s
intvalue += amount
@pstore[key] = intvalue.to_s
intvalue
end
end
|
#key?(key, options = {}) ⇒ Boolean
18
19
20
|
# File 'lib/moneta/adapters/pstore.rb', line 18
def key?(key, options = {})
@pstore.transaction(true) { @pstore.root?(key) }
end
|
#load(key, options = {}) ⇒ Object
22
23
24
|
# File 'lib/moneta/adapters/pstore.rb', line 22
def load(key, options = {})
@pstore.transaction(true) { @pstore[key] }
end
|
#store(key, value, options = {}) ⇒ Object
26
27
28
|
# File 'lib/moneta/adapters/pstore.rb', line 26
def store(key, value, options = {})
@pstore.transaction { @pstore[key] = value }
end
|