Module: SocialEngine::Friendable

Defined in:
app/models/social_engine/friendable.rb

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#is_friendableObject



3
4
5
6
7
8
9
10
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
# File 'app/models/social_engine/friendable.rb', line 3

def is_friendable

  # Setup conditions
  active = ["confirmed = ? AND rejected = ?", true, false]
  pending = ["confirmed = ?", false]
  requested = ["confirmed = ? AND rejected = ?", false, false]
  rejected = ["rejected = ?", true]

  # Active friendships
  has_many :friendorings, :class_name=>'Friending',
           :foreign_key=>:friendee_id, :conditions=>active
  has_many :friendeeings, :class_name=>'Friending',
           :foreign_key=>:friendor_id, :conditions=>active
  # Pending friend requests from the user
  has_many :pending_friendships, :class_name=>'Friending',
           :foreign_key=>:friendor_id, :conditions=>pending
  # Pending friend requests to the user
  has_many :friend_requests, :class_name=>'Friending',
           :foreign_key=>:friendee_id, :conditions=>requested
  # Friend requests rejected by the user
  has_many :friend_rejections, :class_name=>'Friending',
           :foreign_key=>:friendee_id, :conditions=>rejected

  # Friend relations (these return collections of Users)
  has_many :friendors, :through=>:friendorings, :class_name=>'User'
  has_many :friendees, :through=>:friendeeings, :class_name=>'User'
  has_many :pending_friends, :through=>:pending_friendships,
           :source=>:friendee, :class_name=>'User'
  has_many :requesting_friends, :through=>:friend_requests,
           :source=>:friendor, :class_name=>'User'
  has_many :rejected_friends, :through=>:friend_rejections,
           :source=>:friendor, :class_name=>'User'

  include InstanceMethods
end