Class: Messaging::Adapters::Postgres::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/messaging/adapters/postgres/stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Stream

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Should not be used directly. Use Messaging.stream or Messaging::Adapters::Postgres::Store#stream



13
14
15
# File 'lib/messaging/adapters/postgres/stream.rb', line 13

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameString (readonly)

Returns the name of the stream.

Returns:

  • (String)

    the name of the stream



6
7
8
# File 'lib/messaging/adapters/postgres/stream.rb', line 6

def name
  @name
end

Instance Method Details

#current_position-1, Integer

The current position of the last message in the stream

Returns:

  • (-1)

    if the stream is empty -1 will be returned

  • (Integer)

    the stream position of the last message in the stream



26
27
28
# File 'lib/messaging/adapters/postgres/stream.rb', line 26

def current_position
  messages.maximum(:stream_position) || -1
end

#inspectObject



30
31
32
33
# File 'lib/messaging/adapters/postgres/stream.rb', line 30

def inspect
  info = "current_position: #{current_position}"
  "#<Stream:#{name}> #{info}>"
end

#messagesActiveRecord::Relation

Access to all messages in the stream sorted by stream_position

Returns:

  • (ActiveRecord::Relation)


19
20
21
# File 'lib/messaging/adapters/postgres/stream.rb', line 19

def messages
  SerializedMessage.where(stream: name).order(:stream_position)
end