Class: Messaging::Adapters::Postgres::Stream
- Inherits:
-
Object
- Object
- Messaging::Adapters::Postgres::Stream
- Defined in:
- lib/messaging/adapters/postgres/stream.rb
Instance Attribute Summary collapse
-
#category ⇒ String
readonly
The stream category.
-
#id ⇒ String
readonly
The stream id.
-
#name ⇒ String
readonly
The name of the stream.
Instance Method Summary collapse
-
#current_position ⇒ -1, Integer
The current position of the last message in the stream.
-
#initialize(name) ⇒ Stream
constructor
private
Should not be used directly.
- #inspect ⇒ Object
-
#messages ⇒ ActiveRecord::Relation
Access to all messages in the stream sorted by stream_position.
- #to_s ⇒ Object
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
#category ⇒ String (readonly)
Returns the stream category.
9 10 11 |
# File 'lib/messaging/adapters/postgres/stream.rb', line 9 def category @category end |
#id ⇒ String (readonly)
Returns the stream id.
12 13 14 |
# File 'lib/messaging/adapters/postgres/stream.rb', line 12 def id @id end |
#name ⇒ String (readonly)
Returns 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
33 34 35 |
# File 'lib/messaging/adapters/postgres/stream.rb', line 33 def current_position .maximum(:stream_position) || -1 end |
#inspect ⇒ Object
41 42 43 44 |
# File 'lib/messaging/adapters/postgres/stream.rb', line 41 def inspect info = "current_position: #{current_position}" "#<Stream:#{name}> #{info}>" end |
#messages ⇒ ActiveRecord::Relation
Access to all messages in the stream sorted by stream_position
26 27 28 |
# File 'lib/messaging/adapters/postgres/stream.rb', line 26 def SerializedMessage.where(stream_category: category, stream_id: id).order(:stream_position) end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/messaging/adapters/postgres/stream.rb', line 37 def to_s name end |