-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
gateway.rb
64 lines (57 loc) · 1.28 KB
/
gateway.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'rom/gateway'
require 'rom/memory/storage'
require 'rom/memory/commands'
module ROM
module Memory
# In-memory gateway interface
#
# @example
# gateway = ROM::Memory::Gateway.new
# gateway.dataset(:users)
# gateway[:users].insert(name: 'Jane')
#
# @api public
class Gateway < ROM::Gateway
adapter :memory
# @return [Object] default logger
#
# @api public
attr_reader :logger
# @api private
def initialize
@connection = Storage.new
end
# Set default logger for the gateway
#
# @param [Object] logger object
#
# @api public
def use_logger(logger)
@logger = logger
end
# Register a dataset in the gateway
#
# If dataset already exists it will be returned
#
# @return [Dataset]
#
# @api public
def dataset(name)
self[name] || connection.create_dataset(name)
end
# @see ROM::Gateway#dataset?
def dataset?(name)
connection.key?(name)
end
# Return dataset with the given name
#
# @param (see ROM::Gateway#[])
# @return [Memory::Dataset]
#
# @api public
def [](name)
connection[name]
end
end
end
end