Module: PrivateMessages::Models::PrivateMessage::ClassMethods

Defined in:
lib/private_messages/models/private_message.rb

Instance Method Summary collapse

Instance Method Details

#around_user(user) ⇒ Object



21
22
23
# File 'lib/private_messages/models/private_message.rb', line 21

def around_user(user)
  klass_name.constantize.where("sender_id = ? or recipient_id = ?", user.id, user.id)
end

#is_private_message(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/private_messages/models/private_message.rb', line 10

def is_private_message(options = {})
  class_attribute :options
  self.options = options

  klass_name = options[:class_name] ||= "User"

  belongs_to :sender, :class_name => klass_name, :foreign_key => 'sender_id'
  belongs_to :recipient, :class_name => klass_name, :foreign_key => 'recipient_id'

  scope :unread, where("read_at is null")

  def around_user(user)
    klass_name.constantize.where("sender_id = ? or recipient_id = ?", user.id, user.id)
  end

  unless included_modules.include? InstanceMethods
    include InstanceMethods
  end
end