Module: ActsAsMessageable::Relation

Extended by:
T::Helpers, T::Sig
Defined in:
lib/acts_as_messageable/relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#relation_contextObject

Returns the value of attribute relation_context.



10
11
12
# File 'lib/acts_as_messageable/relation.rb', line 10

def relation_context
  @relation_context
end

Instance Method Details

#conversationsArray<ActsAsMessageable::Message>, ActiveRecord::Relation

Returns:



30
31
32
33
# File 'lib/acts_as_messageable/relation.rb', line 30

def conversations
  relation = T.cast(self, ActiveRecord::Relation)
  relation.map { |message| message.root.subtree.order('id desc').first }.uniq
end

#process(context = relation_context) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/acts_as_messageable/relation.rb', line 18

def process(context = relation_context)
  relation = T.cast(self, ActiveRecord::Relation)

  relation.each do |message|
    yield(message) if block_given?
    context.delete_message(message) if message.removed
    context.restore_message(message) if message.restored
  end
end