Class: Basquiat::Adapters::Test
- Inherits:
-
Base
- Object
- Base
- Basquiat::Adapters::Test
show all
- Defined in:
- lib/basquiat/adapters/test_adapter.rb
Overview
An adapter to be used in testing
Instance Attribute Summary collapse
Attributes inherited from Base
#procs
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#adapter_options, #default_options, #disconnect, #initialize, register_strategy, strategies, #strategies, strategy
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
17
18
19
|
# File 'lib/basquiat/adapters/test_adapter.rb', line 17
def options
@options
end
|
Class Method Details
.clean ⇒ Object
12
13
14
|
# File 'lib/basquiat/adapters/test_adapter.rb', line 12
def clean
@events&.clear
end
|
.events ⇒ Object
8
9
10
|
# File 'lib/basquiat/adapters/test_adapter.rb', line 8
def events
@events ||= Hash.new { |hash, key| hash[key] = [] }
end
|
Instance Method Details
#base_options ⇒ Object
19
20
21
22
|
# File 'lib/basquiat/adapters/test_adapter.rb', line 19
def base_options
@event_names = []
{ host: '127.0.0.1', port: 123_456, durable: true }
end
|
#connected? ⇒ Boolean
43
44
45
|
# File 'lib/basquiat/adapters/test_adapter.rb', line 43
def connected?
true
end
|
#events(key) ⇒ Object
28
29
30
|
# File 'lib/basquiat/adapters/test_adapter.rb', line 28
def events(key)
self.class.events[key]
end
|
#listen ⇒ Object
37
38
39
40
41
|
# File 'lib/basquiat/adapters/test_adapter.rb', line 37
def listen(*)
event = subscribed_event
msg = self.class.events[event].shift
msg ? procs[event].call(BaseMessage.new(msg)) : nil
end
|
#publish(event, message, _single_message = true) ⇒ Object
24
25
26
|
# File 'lib/basquiat/adapters/test_adapter.rb', line 24
def publish(event, message, _single_message = true)
self.class.events[event] << Basquiat::Json.encode(message)
end
|
#subscribe_to(event_name, proc) ⇒ Object
32
33
34
35
|
# File 'lib/basquiat/adapters/test_adapter.rb', line 32
def subscribe_to(event_name, proc)
@event_names << event_name
procs[event_name] = proc
end
|