Class: MessageStore::EventStore::Get::Last

Inherits:
Object
  • Object
show all
Includes:
Log::Dependency
Defined in:
lib/message_store/event_store/get/last.rb

Constant Summary collapse

Assertions =
Get::Assertions

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(session: nil) ⇒ Object



12
13
14
15
16
# File 'lib/message_store/event_store/get/last.rb', line 12

def self.build(session: nil)
  instance = new
  instance.configure(session: session)
  instance
end

.call(stream_name, **build_arguments) ⇒ Object



18
19
20
21
# File 'lib/message_store/event_store/get/last.rb', line 18

def self.call(stream_name, **build_arguments)
  instance = build(**build_arguments)
  instance.(stream_name)
end

Instance Method Details

#call(stream_name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/message_store/event_store/get/last.rb', line 35

def call(stream_name)
  logger.trace { "Getting last message of stream (Stream Name: #{stream_name})" }

  begin
    message_data, * = read_stream.(
      stream_name,
      position: :head,
      direction: :backward,
      batch_size: 1
    )
  rescue ::EventStore::HTTP::ReadStream::StreamNotFoundError
  end

  logger.debug { "Got last message of stream (Stream Name: #{stream_name}, Message Type: #{message_data&.type.inspect}, Position: #{message_data&.position.inspect}, Global Position: #{message_data&.global_position.inspect})" }

  message_data
end

#configure(session: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/message_store/event_store/get/last.rb', line 23

def configure(session: nil)
  session = Session.configure(self, session: session)

  read_stream = ::EventStore::HTTP::ReadStream.configure(
    self,
    session: session
  )

  read_stream.embed_body
  read_stream.output_schema = Result
end