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



19
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
# File 'lib/event_store_client/adapters/grpc/commands/streams/link_to.rb', line 19

def call(stream_name, events, options: {})
  events.each do |event|
    payload = [
      request.new(
        options: {
          stream_identifier: {
            streamName: stream_name
          },
          any: {}
        }
      ),
      request.new(
        proposed_message: {
          id: {
            string: event.id
          },
          data: event.title,
          custom_metadata: JSON.generate(
            "type": '$>',
            "content-type": 'application/vnd.eventstore.events+json',
            "created_at": Time.now
          ),
          metadata: event..tap { |h| h['type'] = '$>' }
        }
      )
    ]
    service.append(payload, metadata: )
  end
  Success()
end