Class: Artery::NoBrainer::Message

Inherits:
Object
  • Object
show all
Includes:
MessageModel, NoBrainer::Document
Defined in:
lib/artery/no_brainer/message.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MessageModel

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

Class Method Details

.after_index(model, index) ⇒ Object



27
28
29
# File 'lib/artery/no_brainer/message.rb', line 27

def after_index(model, index)
  where(model: model, :_index.gt => index).order(:_index)
end

.delete_oldObject



35
36
37
# File 'lib/artery/no_brainer/message.rb', line 35

def delete_old
  where(:created_at_f.lt => MAX_MESSAGE_AGE.ago.to_f).delete_all
end

.latest_index(model) ⇒ Object



31
32
33
# File 'lib/artery/no_brainer/message.rb', line 31

def latest_index(model)
  where(model: model).max(:_index)&.index.to_i
end

Instance Method Details

#_create(options = {}) ⇒ Object



40
41
42
43
44
# File 'lib/artery/no_brainer/message.rb', line 40

def _create(options = {})
  now = Time.zone.now
  self.created_at_f = now.to_f.round(6) unless created_at_f_changed?
  super
end

#previous_indexObject



46
47
48
49
50
# File 'lib/artery/no_brainer/message.rb', line 46

def previous_index
  return 0 unless index

  self.class.where(model: model, :_index.lt => index).max(:_index)&.index
end

#to_arteryObject



52
53
54
# File 'lib/artery/no_brainer/message.rb', line 52

def to_artery
  data.merge('_index' => index)
end