Class: EventStoreClient::GRPC::Commands::Streams::LinkTo

Inherits:
Command
  • Object
show all
Includes:
Configuration
Defined in:
lib/event_store_client/adapters/grpc/commands/streams/link_to.rb

Instance Method Summary collapse

Methods included from Configuration

#config

Methods inherited from Command

inherited, #metadata

Instance Method Details

#call(stream_name, events, options: {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/event_store_client/adapters/grpc/commands/streams/link_to.rb', line 20

def call(stream_name, events, options: {})
  events.each_with_index do |event, index|
     = JSON.generate(
      "type": '$>',
      "created_at": Time.now,
      "encryption": event.['encryption'] || ''
    )

     = event..tap do |h|
      h['type'] = '$>'
      h['content-type'] = 'application/json'
      h.delete('encryption')
    end

    event_id = event.id
    event_id = SecureRandom.uuid if event.id.nil? || event.id.empty?

    payload = [
      request.new(
        options: {
          stream_identifier: {
            streamName: stream_name
          },
          any: {}
        }
      ),
      request.new(
        proposed_message: {
          id: {
            string: event_id
          },
          data: event.title,
          custom_metadata: ,
          metadata: 
        }
      )
    ]
    service.append(payload, metadata: )
  end
  Success()
end