1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-05 14:57:30 +01:00
metasploit-framework/lib/anemone/storage/pstore.rb
HD Moore b3cc6e19b6 Initial import of an Anemone snapshot
git-svn-id: file:///home/svn/framework3/trunk@10924 4d416f70-5f16-0410-b530-b9f4589650da
2010-11-06 04:34:43 +00:00

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