-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.rb
executable file
·41 lines (33 loc) · 1.04 KB
/
storage.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module Shark
module Storage
extend self
# The configuration used for storage. Defaults here can be overwritten
# using `Storage::configure(options)`, where options are the replacement
# configuration options.
def configuration
@configuration ||= {
# Use the memory adapter to preference speed over scalability
adapter: :memory
}
end
# Overwrite values in the configuration hash with those given in `opts`.
def configure opts
configuration.merge!(opts)
end
# Return the single storage adapter instance
def adapter
@adapter ||= adapter_class.new configuration
end
# Return the class of the adapter to use for storage
def adapter_class
@@adapters[configuration[:adapter]]
end
# Register a new class that can be used as a storage adapter
def register_adapter name, klass
(@@adapters ||= {})[name] = klass
end
end
end
# Include packaged adapters
require_relative 'storage/adapters/abstract'
require_relative 'storage/adapters/memory'