Module: Stex::Acts::Messagable::ClassMethods
- Defined in:
- lib/stex/acts/messagable.rb
Instance Method Summary collapse
-
#acts_as_messagable(options = {}) ⇒ Object
Adds the functionality to send and receive messages to this
ActiveRecordclass.
Instance Method Details
#acts_as_messagable(options = {}) ⇒ Object
Adds the functionality to send and receive messages to this ActiveRecord class
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/stex/acts/messagable.rb', line 171 def acts_as_messagable( = {}) klass = Stex::Acts::Messagable. #Add has_many associations for easy message management has_many :received_messages, :class_name => klass, :as => :recipient, :conditions => {:sender_copy => false} has_many :unread_messages, :class_name => klass, :as => :recipient, :conditions => {:read_at => nil, :sender_copy => false} has_many :read_messages, :class_name => klass, :as => :recipient, :conditions => ['read_at IS NOT NULL AND sender_copy = ?', false] has_many :sent_messages, :class_name => klass, :as => :sender, :conditions => {:sender_copy => true} cattr_accessor :acts_as_messagable_options = {} #Sender and recipient procs [:sender_name] = [:sender_name] || lambda { |r| "#{r.class.human_name}: #{r.id}" } [:recipient_name] = [:recipient_name] || lambda { |r| "#{r.class.human_name}: #{r.id}" } #Forward and message handler proc [:forward_to] = [:forward_to] if .has_key?(:forward_to) [:handler] = [:handler] if .has_key?(:handler) #optional recipients [:optional_recipients] = [:optional_recipients] if [:optional_recipients] [:store_additional_recipients] = [:store_additional_recipients] self. = .freeze include Stex::Acts::Messagable::InstanceMethods end |