Class: Flu::Dummy::InMemoryEventPublisher
- Inherits:
-
EventPublisher
- Object
- EventPublisher
- Flu::Dummy::InMemoryEventPublisher
- Defined in:
- lib/flu-rails/dummy/in_memory_event_publisher.rb
Instance Attribute Summary collapse
-
#ordered_published_event_routing_keys ⇒ Object
readonly
Returns the value of attribute ordered_published_event_routing_keys.
-
#published_events_by_routing_key ⇒ Object
readonly
Returns the value of attribute published_events_by_routing_key.
Instance Method Summary collapse
- #clear ⇒ Object
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
- #events_count ⇒ Object
- #fetch_events(routing_key) ⇒ Object
-
#initialize(configuration) ⇒ InMemoryEventPublisher
constructor
A new instance of InMemoryEventPublisher.
- #publish(event, persistent = true) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ InMemoryEventPublisher
Returns a new instance of InMemoryEventPublisher.
7 8 9 10 11 12 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 7 def initialize(configuration) @logger = configuration.logger @configuration = configuration @published_events_by_routing_key = {} @ordered_published_event_routing_keys = [] end |
Instance Attribute Details
#ordered_published_event_routing_keys ⇒ Object (readonly)
Returns the value of attribute ordered_published_event_routing_keys.
5 6 7 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 5 def ordered_published_event_routing_keys @ordered_published_event_routing_keys end |
#published_events_by_routing_key ⇒ Object (readonly)
Returns the value of attribute published_events_by_routing_key.
5 6 7 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 5 def published_events_by_routing_key @published_events_by_routing_key end |
Instance Method Details
#clear ⇒ Object
41 42 43 44 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 41 def clear @published_events_by_routing_key = {} @ordered_published_event_routing_keys = [] end |
#connect ⇒ Object
21 22 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 21 def connect end |
#connected? ⇒ Boolean
24 25 26 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 24 def connected? true end |
#disconnect ⇒ Object
28 29 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 28 def disconnect end |
#events_count ⇒ Object
31 32 33 34 35 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 31 def events_count @published_events_by_routing_key.map do | key, value | value.size end.sum end |
#fetch_events(routing_key) ⇒ Object
37 38 39 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 37 def fetch_events(routing_key) @published_events_by_routing_key[routing_key] end |
#publish(event, persistent = true) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 14 def publish(event, persistent=true) routing_key = event.to_routing_key published_events_by_routing_key[routing_key] ||= [] published_events_by_routing_key[routing_key].push(event) @ordered_published_event_routing_keys.push(routing_key) end |