Module: Msg::ActiveRecordClassMethods

Defined in:
lib/msg/receivers.rb

Instance Method Summary collapse

Instance Method Details

#messaging_group(name) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/msg/receivers.rb', line 37

def messaging_group(name)
  if definition = messaging_groups(name)
    definition.call()
  else
    self.send name
  end
end

#messaging_groupsObject

Messaging groups are usually defined by passing a :groups parameter to ‘receives_messages`, but you can also override the messaging_groups methods if your groups don’t resolve to scopes or other class methods.



21
22
23
# File 'lib/msg/receivers.rb', line 21

def messaging_groups
  Thread.current["messaging_groups_#{self.to_s.underscore}"] ||= []
end

#messaging_groups=(groups) ⇒ Object

Messaging groups can be passed in as procs or method names. Usually it’s just a list of scopes, which you can supply as a simple array of names.



28
29
30
31
32
33
34
35
# File 'lib/msg/receivers.rb', line 28

def messaging_groups=(groups)
  if groups.is_a?(Array)
    groups = groups.each_with_object({}) do |grp, hash|
      hash[grp] = lambda { self.send grp }
    end
  end
  Thread.current["messaging_groups_#{self.to_s.underscore}"] = groups
end

#receives_messages(options = {}) ⇒ Object



12
13
14
15
# File 'lib/msg/receivers.rb', line 12

def receives_messages(options={})
  has_many :envelopes, :as => :receiver, :class_name => "Msg::Envelope"
  Msg.add_receiving_class(self, options)
end