Class: Messaging::Adapters::Postgres::Category

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Category

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.category or Store#category



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

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameString (readonly)

Returns the name of the category.

Returns:

  • (String)

    the name of the category



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

def name
  @name
end

Instance Method Details

#delete_messages_older_than!(time) ⇒ Object



27
28
29
30
31
32
# File 'lib/messaging/adapters/postgres/category.rb', line 27

def delete_messages_older_than!(time)
  SerializedMessage.transaction do
    ActiveRecord::Base.connection.execute "SET LOCAL statement_timeout = '0'"
    messages_older_than(time).delete_all
  end
end

#inspectObject



34
35
36
# File 'lib/messaging/adapters/postgres/category.rb', line 34

def inspect
  "#<Category:#{name}>>"
end

#messagesActiveRecord::Relation

Access to all messages in the category sorted by created_at

Returns:

  • (ActiveRecord::Relation)


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

def messages
  SerializedMessage.where(stream_category: name).order(:created_at)
end

#messages_older_than(time) ⇒ Object



23
24
25
# File 'lib/messaging/adapters/postgres/category.rb', line 23

def messages_older_than(time)
  messages.where('created_at < ?', time)
end