CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/anemone/storage/pstore.rb
Views: 11779
1
require 'pstore'
2
require 'forwardable'
3
4
module Anemone
5
module Storage
6
class PStore
7
extend Forwardable
8
9
def_delegators :@keys, :has_key?, :keys, :size
10
11
def initialize(file)
12
File.delete(file) if File.exist?(file)
13
@store = ::PStore.new(file)
14
@keys = {}
15
end
16
17
def [](key)
18
@store.transaction { |s| s[key] }
19
end
20
21
def []=(key,value)
22
@keys[key] = nil
23
@store.transaction { |s| s[key] = value }
24
end
25
26
def delete(key)
27
@keys.delete(key)
28
@store.transaction { |s| s.delete key}
29
end
30
31
def each
32
@keys.each_key do |key|
33
value = nil
34
@store.transaction { |s| value = s[key] }
35
yield key, value
36
end
37
end
38
39
def merge!(hash)
40
@store.transaction do |s|
41
hash.each { |key, value| s[key] = value; @keys[key] = nil }
42
end
43
self
44
end
45
46
def close; end
47
48
end
49
end
50
end
51
52