Class: Moneta::Adapters::PStore

Inherits:
PStore
  • Object
show all
Includes:
Defaults
Defined in:
lib/moneta/adapters/pstore.rb

Instance Method Summary collapse

Methods included from Defaults

#[]=, #fetch

Constructor Details

#initialize(options = {}) ⇒ PStore

Returns a new instance of PStore.



8
9
10
11
# File 'lib/moneta/adapters/pstore.rb', line 8

def initialize(options = {})
  options[:path] ||= ::File.join Dir.pwd, 'data.pstore'
  super options[:path]
end

Instance Method Details

#[](key) ⇒ Object



25
26
27
28
29
30
# File 'lib/moneta/adapters/pstore.rb', line 25

def [](key)
  transaction true do
    struct = super key_for(key)
    struct ? struct['value'] : nil
  end
end

#clearObject



49
50
51
52
53
54
55
# File 'lib/moneta/adapters/pstore.rb', line 49

def clear(*)
  transaction do
    @table.keys.each do |key|
      delete key
    end
  end
end

#delete(key) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/moneta/adapters/pstore.rb', line 32

def delete(key)
  struct = if @transaction
    super key_for(key)
  else
    transaction do
      super key_for(key)
    end
  end
  struct ? struct['value'] : nil
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/moneta/adapters/pstore.rb', line 13

def key?(key)
  transaction do
    root? key_for(key)
  end
end

#keysObject



19
20
21
22
23
# File 'lib/moneta/adapters/pstore.rb', line 19

def keys
  transaction true do
    roots
  end
end

#store(key, value) ⇒ Object



43
44
45
46
47
# File 'lib/moneta/adapters/pstore.rb', line 43

def store(key, value, *)
  transaction do
    (@table[key_for(key)] ||= {})['value'] = value
  end
end