Class: EventStoreClient::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/event_store_client/connection.rb

Instance Method Summary collapse

Instance Method Details

#consume_feed(stream, subscription) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/event_store_client/connection.rb', line 30

def consume_feed(stream, subscription)
  response = client.consume_feed(stream, subscription)
  return [] unless response.body
  body = JSON.parse(response.body)

  ack = body['links'].find { |link| link['relation'] == 'ackAll' }
  return unless ack
  ack_uri = ack['uri']
  events = body['entries'].map do |entry|
    deserialize_event(entry)
  end
  client.ack(ack_uri)
  events
end

#delete_stream(stream) ⇒ Object



20
# File 'lib/event_store_client/connection.rb', line 20

def delete_stream(stream); end

#join_streams(name, streams) ⇒ Object



22
23
24
# File 'lib/event_store_client/connection.rb', line 22

def join_streams(name, streams)
  client.join_streams(name, streams)
end


45
46
47
48
49
# File 'lib/event_store_client/connection.rb', line 45

def link_to(stream, events, expected_version: nil)
  client.link_to(stream, events, expected_version: expected_version)

  true
end

#publish(stream:, events:, expected_version: nil) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/event_store_client/connection.rb', line 5

def publish(stream:, events:, expected_version: nil)
  serialized_events = events.map { |event| mapper.serialize(event) }
  client.append_to_stream(
    stream, serialized_events, expected_version: expected_version
  )
  serialized_events
end

#read(stream, direction:, start:, all:, resolve_links: true) ⇒ Object



13
14
15
16
17
18
# File 'lib/event_store_client/connection.rb', line 13

def read(stream, direction:, start:, all:, resolve_links: true)
  return read_all_from_stream(stream, start: start, resolve_links: resolve_links) if all
  read_from_stream(
    stream, direction: direction, start: start, resolve_links: resolve_links
  )
end

#subscribe(stream, name:) ⇒ Object



26
27
28
# File 'lib/event_store_client/connection.rb', line 26

def subscribe(stream, name:)
  client.subscribe_to_stream(stream, name)
end