Class: CoverRage::Stores::Pstore

Inherits:
Object
  • Object
show all
Defined in:
lib/cover_rage/stores/pstore.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Pstore

Returns a new instance of Pstore.



9
10
11
# File 'lib/cover_rage/stores/pstore.rb', line 9

def initialize(path)
  @store = PStore.new(path, true)
end

Instance Method Details

#clearObject



42
43
44
45
46
47
48
49
50
# File 'lib/cover_rage/stores/pstore.rb', line 42

def clear
  if @transaction
    @store.keys.each { @store.delete(_1) }
  else
    @store.transaction do
      @store.keys.each { @store.delete(_1) }
    end
  end
end

#listObject



32
33
34
35
36
37
38
39
40
# File 'lib/cover_rage/stores/pstore.rb', line 32

def list
  if @transaction
    @store.keys.map { @store[_1] }
  else
    @store.transaction do
      @store.keys.map { @store[_1] }
    end
  end
end

#transactionObject



13
14
15
16
17
18
19
20
# File 'lib/cover_rage/stores/pstore.rb', line 13

def transaction
  @store.transaction do
    @transaction = true
    yield
  ensure
    @transaction = false
  end
end

#update(records) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/cover_rage/stores/pstore.rb', line 22

def update(records)
  if @transaction
    records.each { @store[_1.path] = _1 }
  else
    @store.transaction do
      records.each { @store[_1.path] = _1 }
    end
  end
end