Sha256: 9aacdba76d1646641d73215e9a7e5866a9ea0f103e2dd1e276745600a15246b1

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module Messaging
  module Adapters
    class Postgres
      class Stream
        # @return [String] the name of the stream
        attr_reader :name

        # Should not be used directly.
        # Use {Messaging.stream} or {Store#stream}
        # @api private
        # @see Messaging.stream
        # @see Store.stream
        def initialize(name)
          @name = name
        end

        # Access to all messages in the stream sorted by stream_position
        # @return [ActiveRecord::Relation]
        def messages
          SerializedMessage.where(stream: name).order(:stream_position)
        end

        # The current position of the last message in the stream
        # @return [-1] if the stream is empty -1 will be returned
        # @return [Integer] the stream position of the last message in the stream
        def current_position
          messages.maximum(:stream_position) || -1
        end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
messaging-3.4.3 lib/messaging/adapters/postgres/stream.rb
messaging-3.4.2 lib/messaging/adapters/postgres/stream.rb
messaging-3.4.1 lib/messaging/adapters/postgres/stream.rb