-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathin_memory.rb
48 lines (39 loc) · 944 Bytes
/
in_memory.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
# frozen_string_literal: true
module RealWorld
module Ports
module Router
class InMemory
def initialize
@queries = {}
@commands = {}
end
def register_cell(cell)
@queries = @queries.merge(cell.queries)
@commands = @commands.merge(cell.commands)
end
def query(name)
@queries.fetch(name)
end
def command(name)
@commands.fetch(name)
end
def query?(name)
@queries.key?(name)
end
def command?(name)
@commands.key?(name)
end
def queries
@queries.map { |name, op| [name, { params: op.parameters }] }.to_h
end
def commands
@commands.map { |name, op| [name, { params: op.parameters }] }.to_h
end
def clear
@queries.clear
@commands.clear
end
end
end
end
end