Class: Artery::ActiveRecord::Message

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
MessageModel
Defined in:
lib/artery/active_record/message.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MessageModel

#publish_to_artery, #route, #to_artery, #uri, #uri=

Class Method Details

.after_index(model, index) ⇒ Object



17
18
19
20
# File 'lib/artery/active_record/message.rb', line 17

def after_index(model, index)
  where(model: model)
    .where(arel_table[:id].gt(index)).order(:id)
end

.delete_oldObject



29
30
31
32
# File 'lib/artery/active_record/message.rb', line 29

def delete_old
  max_aged_id = where(arel_table[:created_at].lt(MAX_MESSAGE_AGE.ago)).maximum(:id)
  where(arel_table[:id].lteq(max_aged_id)).delete_all if max_aged_id.to_i.positive?
end

.latest_index(model) ⇒ Object



22
23
24
25
26
27
# File 'lib/artery/active_record/message.rb', line 22

def latest_index(model)
  last_message_id = where(model: model).maximum(:id).to_i
  return last_message_id unless last_message_id.zero?

  Artery.model_info_class.last_published_id_for(model)
end

Instance Method Details

#previous_indexObject



35
36
37
38
39
40
# File 'lib/artery/active_record/message.rb', line 35

def previous_index
  scope = self.class.where(model: model).order(:id)
  scope = scope.where(self.class.arel_table[:id].lt(index)) if index

  scope.select(:id).last&.id.to_i
end