Class: Messaging::Adapters::Test::Store
- Inherits:
-
Object
- Object
- Messaging::Adapters::Test::Store
- Defined in:
- lib/messaging/adapters/test/store.rb
Overview
Message store adapter used for testing. It stores all messages in memory. Prefer accessing the message store through Messaging.message_store instead of using it directly.
Instance Attribute Summary collapse
-
#messages ⇒ Array<Messaging::Message>
readonly
Access to all messages.
-
#streams ⇒ Streams
readonly
All the streams in the store.
Instance Method Summary collapse
-
#call(message) ⇒ Messaging::Message
Writes the message to the store Skips messages that hasn’t defined a stream name.
- #clear! ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
-
#stream(name) ⇒ Stream
Get a specific stream by name.
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
32 33 34 |
# File 'lib/messaging/adapters/test/store.rb', line 32 def initialize clear! end |
Instance Attribute Details
#messages ⇒ Array<Messaging::Message> (readonly)
Access to all messages.
27 28 29 |
# File 'lib/messaging/adapters/test/store.rb', line 27 def @messages end |
#streams ⇒ Streams (readonly)
Returns all the streams in the store.
30 31 32 |
# File 'lib/messaging/adapters/test/store.rb', line 30 def streams @streams end |
Instance Method Details
#call(message) ⇒ Messaging::Message
Writes the message to the store Skips messages that hasn’t defined a stream name
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/messaging/adapters/test/store.rb', line 54 def call() return unless .stream_name stream = stream(.stream_name) ExpectedVersion.new(.expected_version || :any).match!(stream.current_position) = .class.new(.attributes.merge(stream_position: stream.current_position + 1)) @messages << stream. << end |
#clear! ⇒ Object
43 44 45 46 |
# File 'lib/messaging/adapters/test/store.rb', line 43 def clear! @streams = Hash.new { |h, k| h[k] = Stream.new(k) } @messages = [] end |
#stream(name) ⇒ Stream
Get a specific stream by name
39 40 41 |
# File 'lib/messaging/adapters/test/store.rb', line 39 def stream(name) streams[name] end |