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
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#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.
- #category(name) ⇒ Object
- #clear! ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
-
#messages_in_streams(*streams) ⇒ Array<Messaging::Message>
Access to all messages in the given streams.
-
#stream(name) ⇒ Stream
Get a specific stream by name.
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
36 37 38 39 |
# File 'lib/messaging/adapters/test/store.rb', line 36 def initialize @categories = Categories.new clear! end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
34 35 36 |
# File 'lib/messaging/adapters/test/store.rb', line 34 def categories @categories end |
#messages ⇒ Array<Messaging::Message> (readonly)
Access to all messages.
29 30 31 |
# File 'lib/messaging/adapters/test/store.rb', line 29 def @messages end |
#streams ⇒ Streams (readonly)
Returns all the streams in the store.
32 33 34 |
# File 'lib/messaging/adapters/test/store.rb', line 32 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
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/messaging/adapters/test/store.rb', line 72 def call() return unless .stream_name stream = stream(.stream_name) category = category(.stream_name.split('$').first) ExpectedVersion.new(.expected_version || :any).match!(stream.current_position) = .class.new(.attributes.merge(stream_position: stream.current_position + 1)) @messages << stream. << category. << end |
#category(name) ⇒ Object
48 49 50 |
# File 'lib/messaging/adapters/test/store.rb', line 48 def category(name) categories[name] end |
#clear! ⇒ Object
60 61 62 63 64 |
# File 'lib/messaging/adapters/test/store.rb', line 60 def clear! @streams = Hash.new { |h, k| h[k] = Stream.new(k) } categories.clear! @messages = [] end |
#messages_in_streams(*streams) ⇒ Array<Messaging::Message>
Access to all messages in the given streams
56 57 58 |
# File 'lib/messaging/adapters/test/store.rb', line 56 def (*streams) .select { |m| streams.flatten.map(&:to_s).include? m.stream_name } end |
#stream(name) ⇒ Stream
Get a specific stream by name
44 45 46 |
# File 'lib/messaging/adapters/test/store.rb', line 44 def stream(name) streams[name] end |