Class: Messaging::Adapters::Test
- Inherits:
-
Object
- Object
- Messaging::Adapters::Test
- Defined in:
- lib/messaging/adapters/test.rb,
lib/messaging/adapters/test/store.rb,
lib/messaging/adapters/test/stream.rb,
lib/messaging/adapters/test/category.rb,
lib/messaging/adapters/test/consumer.rb,
lib/messaging/adapters/test/categories.rb
Overview
Public: An adapter useful for test.
Do NOT use this outside tests. All messages will be saved in memory until cleared.
Defined Under Namespace
Classes: Categories, Category, Consumer, Store, Stream
Instance Attribute Summary collapse
-
#topics ⇒ Object
readonly
Public: Used to inspect what have been published.
Instance Method Summary collapse
- #call(message) ⇒ Object
-
#clear_topics ⇒ Object
Resests the topics to a blank state.
- #create_consumer(name, **options) ⇒ Object
-
#initialize ⇒ Test
constructor
A new instance of Test.
- #store ⇒ Object private
Constructor Details
#initialize ⇒ Test
Returns a new instance of Test.
16 17 18 19 20 |
# File 'lib/messaging/adapters/test.rb', line 16 def initialize # See https://www.rubytapas.com/2013/01/11/episode-045-hash-default-value/ # for why this is needed for default values in a Hash @topics = Hash.new { |h, k| h[k] = [] } end |
Instance Attribute Details
#topics ⇒ Object (readonly)
Public: Used to inspect what have been published
It’s a hash keyed on the topic name. Each value is an array of the messages that has been published to the topic
14 15 16 |
# File 'lib/messaging/adapters/test.rb', line 14 def topics @topics end |
Instance Method Details
#call(message) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/messaging/adapters/test.rb', line 22 def call() topics[.topic] << Messaging.routes.consumers.each do |c| Messaging.logger.info "Sending #{} to #{c.queue} with length #{c.queue.length}" c.queue << end end |
#clear_topics ⇒ Object
Resests the topics to a blank state.
Useful to run before each example in specs to not share state.
37 38 39 |
# File 'lib/messaging/adapters/test.rb', line 37 def clear_topics topics.clear end |