Class: EventStoreClient::GRPC::Commands::Streams::Read

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

Constant Summary collapse

StreamNotFound =
Class.new(StandardError)

Instance Method Summary collapse

Methods included from Configuration

#config

Methods inherited from Command

inherited, #metadata

Instance Method Details

#call(name, options: {}) ⇒ Object



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

def call(name, options: {})
  direction =
    EventStoreClient::ReadDirection.new(options[:direction] || 'forwards').to_sym
  opts = {
    stream: {
      stream_identifier: {
        streamName: name
      }
    },
    read_direction: direction,
    resolve_links: options[:resolve_links] || true,
    count: options[:count] || config.per_page,
    uuid_option: {
      string: {}
    },
    no_filter: {}
  }
  options[:start] ||= 0
  if options[:start].zero?
    opts[:stream][:start] = {}
  else
    opts[:stream][:revision] = options[:start]
  end

  events = service.read(request.new(options: opts), metadata: ).map do |res|
    raise StreamNotFound if res.stream_not_found

    deserialize_event(res.event.event)
  end
  Success(events)
rescue StreamNotFound
  Failure(:not_found)
end