Module: Mailboxer::Models::Messageable::ClassMethods

Defined in:
lib/mailboxer/models/messageable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_messageableObject

Converts the model into messageable allowing it to interchange messages and receive notifications



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mailboxer/models/messageable.rb', line 11

def acts_as_messageable
  has_many :messages
  has_many :receipts, :order => 'created_at DESC', :dependent => :delete_all

  if self.table_exists?
    if !self.new.respond_to? :name
      self.class_eval do
      #Returning any kind of indentification you want for the model
        def name
          return "You should add method :name in your Messageable model"
        end
      end
    end

    if !self.new.respond_to? :email
      self.class_eval do
      #Returning the email address of the model
        def email
          return "define_email@on_your.model"
        end
      end
    end

    if !self.new.respond_to? :should_email?
      self.class_eval do
      #Returning whether an email should be sent for this object (Message or Notification)
        def should_email?(object)
          return true
        end
      end
    end
  end
  include Mailboxer::Models::Messageable::InstanceMethods
end