Class: Flu::Dummy::InMemoryEventPublisher

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

Constant Summary

Constants inherited from EventPublisher

EventPublisher::NOT_CONNECTED_MESSAGE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ InMemoryEventPublisher

Returns a new instance of InMemoryEventPublisher.



9
10
11
12
13
14
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 9

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.



7
8
9
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 7

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.



7
8
9
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 7

def published_events_by_routing_key
  @published_events_by_routing_key
end

Instance Method Details

#clearObject



43
44
45
46
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 43

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

#connectObject



23
24
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 23

def connect
end

#connected?Boolean

Returns:

  • (Boolean)


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

def connected?
  true
end

#disconnectObject



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

def disconnect
end

#events_countObject



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

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

#fetch_events(routing_key) ⇒ Object



39
40
41
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 39

def fetch_events(routing_key)
  @published_events_by_routing_key[routing_key]
end

#publish(event, persistent = true) ⇒ Object



16
17
18
19
20
21
# File 'lib/flu-rails/dummy/in_memory_event_publisher.rb', line 16

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