Class: EventStoreClient::GRPC::Commands::Projections::Create

Inherits:
Command
  • Object
show all
Defined in:
lib/event_store_client/adapters/grpc/commands/projections/create.rb

Instance Method Summary collapse

Methods inherited from Command

inherited, #metadata

Methods included from Configuration

#config

Instance Method Details

#call(name, streams) ⇒ Object



17
18
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
# File 'lib/event_store_client/adapters/grpc/commands/projections/create.rb', line 17

def call(name, streams)
  data = <<~STRING
    fromStreams(#{streams})
    .when({
      $any: function(s,e) {
        linkTo("#{name}", e)
      }
    })
  STRING

  options =
    {
      query: data,
      continuous: {
        name: name,
        track_emitted_streams: true
      }
    }

  res = Try do
    service.create(request.new(options: options), metadata: )
  end

  res.error? ? res.to_result : Success()
rescue ::GRPC::Unknown => e
  Failure(:conflict) if e.message.include?('Conflict')
end