Class: Flu::Dummy::InMemoryEventPublisher

Inherits:
EventPublisher show all
Defined in:
lib/flu-rails/dummy/in_memory_event_publisher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keysObject (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_keyObject (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

#clearObject



34
35
36
37
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 34

def clear
  @published_events_by_routing_key      = {}
  @ordered_published_event_routing_keys = []
end

#connectObject



21
22
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 21

def connect
end

#events_countObject



24
25
26
27
28
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 24

def events_count
  @published_events_by_routing_key.map do | key, value |
    value.size
  end.sum
end

#fetch_events(routing_key) ⇒ Object



30
31
32
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 30

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