Class: RubyEventStore::LinkByMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/link_by_metadata.rb

Direct Known Subclasses

LinkByCausationId, LinkByCorrelationId

Instance Method Summary collapse

Constructor Details

#initialize(event_store:, key:, prefix: nil) ⇒ LinkByMetadata

Returns a new instance of LinkByMetadata.


6
7
8
9
10
# File 'lib/ruby_event_store/link_by_metadata.rb', line 6

def initialize(event_store:, key:, prefix: nil)
  @event_store = event_store
  @key = key
  @prefix = prefix || ["$by", key, nil].join("_")
end

Instance Method Details

#call(event) ⇒ Object


12
13
14
15
16
17
18
19
# File 'lib/ruby_event_store/link_by_metadata.rb', line 12

def call(event)
  return unless event..has_key?(@key)

  @event_store.link(
    [event.event_id],
    stream_name: "#{@prefix}#{event..fetch(@key)}"
  )
end