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



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

def initialize(name)
  @name = name
  @category, @id = name.split('$')
end

Instance Attribute Details

#categoryString (readonly)

Returns the stream category.

Returns:

  • (String)

    the stream category



9
10
11
# File 'lib/messaging/adapters/postgres/stream.rb', line 9

def category
  @category
end

#idString (readonly)

Returns the stream id.

Returns:

  • (String)

    the stream id



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

def id
  @id
end

#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



33
34
35
# File 'lib/messaging/adapters/postgres/stream.rb', line 33

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

#inspectObject



41
42
43
44
# File 'lib/messaging/adapters/postgres/stream.rb', line 41

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)


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

def messages
  SerializedMessage.where(stream_category: category, stream_id: id).order(:stream_position)
end

#to_sObject



37
38
39
# File 'lib/messaging/adapters/postgres/stream.rb', line 37

def to_s
  name
end