Class: Messaging::Adapters::Postgres::Store
- Inherits:
-
Object
- Object
- Messaging::Adapters::Postgres::Store
- Defined in:
- lib/messaging/adapters/postgres/store.rb
Overview
Message store adapter using Postgres and ActiveRecord. Prefer accessing the message store through Messaging.message_store instead of using it directly.
Instance Attribute Summary collapse
-
#categories ⇒ Categories
readonly
All the stream categories in the store.
-
#streams ⇒ Streams
readonly
All the streams in the store.
Instance Method Summary collapse
-
#call(message) ⇒ Messaging::Message
Writes the message to Postgres Skips messages that hasn’t defined a stream name We do this to begin with so PG is opt-in per message.
-
#category(name) ⇒ Stream
Get a specific category by name.
-
#initialize ⇒ Store
constructor
private
Should not be used directly.
-
#messages ⇒ SerializedMessage
Access to all messages.
-
#messages_in_streams(*streams) ⇒ ActiveRecord::Relation
Access to all messages in the given streams.
-
#stream(name) ⇒ Stream
Get a specific stream by name.
Constructor Details
#initialize ⇒ Store
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. Access the store though Messaging.message_store or Messaging::Adapters::Store
32 33 34 35 |
# File 'lib/messaging/adapters/postgres/store.rb', line 32 def initialize @streams = Streams.new @categories = Categories.new end |
Instance Attribute Details
#categories ⇒ Categories (readonly)
Returns all the stream categories in the store.
27 28 29 |
# File 'lib/messaging/adapters/postgres/store.rb', line 27 def categories @categories end |
#streams ⇒ Streams (readonly)
Returns all the streams in the store.
23 24 25 |
# File 'lib/messaging/adapters/postgres/store.rb', line 23 def streams @streams end |
Instance Method Details
#call(message) ⇒ Messaging::Message
Writes the message to Postgres Skips messages that hasn’t defined a stream name We do this to begin with so PG is opt-in per message
81 82 83 84 85 |
# File 'lib/messaging/adapters/postgres/store.rb', line 81 def call() return unless .stream_name SerializedMessage.create!(message: ). end |
#category(name) ⇒ Stream
Get a specific category by name
47 48 49 |
# File 'lib/messaging/adapters/postgres/store.rb', line 47 def category(name) categories[name] end |
#messages ⇒ SerializedMessage
Access to all messages. Use with caution in production as there are probably a lot of messages so queries could take a long time or timeout.
61 62 63 |
# File 'lib/messaging/adapters/postgres/store.rb', line 61 def SerializedMessage end |
#messages_in_streams(*streams) ⇒ ActiveRecord::Relation
Access to all messages in the given streams
70 71 72 |
# File 'lib/messaging/adapters/postgres/store.rb', line 70 def (*streams) SerializedMessage.where(stream: streams.flatten.map(&:to_s)).order(:id) end |
#stream(name) ⇒ Stream
Get a specific stream by name
40 41 42 |
# File 'lib/messaging/adapters/postgres/store.rb', line 40 def stream(name) streams[name] end |