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/base.rb
Views: 11779
1
require 'anemone/storage/exceptions'
2
3
module Anemone
4
module Storage
5
class Base
6
7
def initialize(adapter)
8
@adap = adapter
9
10
# verify adapter conforms to this class's methods
11
methods.each do |method|
12
if !@adap.respond_to?(method.to_sym)
13
raise "Storage adapter must support method #{method}"
14
end
15
end
16
end
17
18
def [](key)
19
@adap[key]
20
rescue
21
puts key
22
raise RetrievalError, $!
23
end
24
25
def []=(key, value)
26
@adap[key] = value
27
rescue
28
raise InsertionError, $!
29
end
30
31
def delete(key)
32
@adap.delete(key)
33
rescue
34
raise DeletionError, $!
35
end
36
37
def each
38
@adap.each { |k, v| yield k, v }
39
rescue
40
raise GenericError, $!
41
end
42
43
def merge!(hash)
44
@adap.merge!(hash)
45
rescue
46
raise GenericError, $!
47
end
48
49
def close
50
@adap.close
51
rescue
52
raise CloseError, $!
53
end
54
55
def size
56
@adap.size
57
rescue
58
raise GenericError, $!
59
end
60
61
def keys
62
@adap.keys
63
rescue
64
raise GenericError, $!
65
end
66
67
def has_key?(key)
68
@adap.has_key?(key)
69
rescue
70
raise GenericError, $!
71
end
72
73
end
74
end
75
end
76
77