mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-11-05 14:57:30 +01:00
b3cc6e19b6
git-svn-id: file:///home/svn/framework3/trunk@10924 4d416f70-5f16-0410-b530-b9f4589650da
51 lines
972 B
Ruby
51 lines
972 B
Ruby
require 'pstore'
|
|
require 'forwardable'
|
|
|
|
module Anemone
|
|
module Storage
|
|
class PStore
|
|
extend Forwardable
|
|
|
|
def_delegators :@keys, :has_key?, :keys, :size
|
|
|
|
def initialize(file)
|
|
File.delete(file) if File.exists?(file)
|
|
@store = ::PStore.new(file)
|
|
@keys = {}
|
|
end
|
|
|
|
def [](key)
|
|
@store.transaction { |s| s[key] }
|
|
end
|
|
|
|
def []=(key,value)
|
|
@keys[key] = nil
|
|
@store.transaction { |s| s[key] = value }
|
|
end
|
|
|
|
def delete(key)
|
|
@keys.delete(key)
|
|
@store.transaction { |s| s.delete key}
|
|
end
|
|
|
|
def each
|
|
@keys.each_key do |key|
|
|
value = nil
|
|
@store.transaction { |s| value = s[key] }
|
|
yield key, value
|
|
end
|
|
end
|
|
|
|
def merge!(hash)
|
|
@store.transaction do |s|
|
|
hash.each { |key, value| s[key] = value; @keys[key] = nil }
|
|
end
|
|
self
|
|
end
|
|
|
|
def close; end
|
|
|
|
end
|
|
end
|
|
end
|