Module: PrivateMail::ClassMethods

Defined in:
lib/private_mail.rb

Overview

declare the class level helper methods which will load the relevant instance methods defined below when invoked

Instance Method Summary collapse

Instance Method Details

#acts_as_messageable(options = {}) ⇒ Object

enables a class to send and receive messages to members of the same class - currently assumes the model is of class type ‘User’, some modifications to the migrations and model classes will need to be made to use a model of different type.

options:

  • :received - the mailbox type to store received messages (defaults to :inbox)

  • :sent - the mailbox type to store sent messages (defaults to :sentbox)

  • :deleted - the mailbox type to store deleted messages (defaults to :trash)

example:

acts_as_messageable :received => :in, :sent => :sent, :deleted => :garbage


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/private_mail.rb', line 28

def acts_as_messageable(options = {})
  cattr_accessor :mailbox_types
  has_many :mail_items, :order => 'created_at DESC', :dependent => :delete_all
  
  self.mailbox_types = {
    :received => :inbox,
    :sent => :sentbox,
    :deleted => :trash
  }.merge(options)
  
  include PrivateMail::InstanceMethods
end