Module: HasManyFriends::UserExtensions::ClassMethods

Defined in:
lib/has_many_friends.rb

Instance Method Summary collapse

Instance Method Details

#has_many_friends(options = {}) ⇒ Object



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
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/has_many_friends.rb', line 10

def has_many_friends(options={})
  has_many :friendships_by_me,
           :foreign_key => 'user_id',
           :class_name => 'Friendship'
  
  has_many :friendships_for_me,
           :foreign_key => 'friend_id',
           :class_name => 'Friendship'
  
  has_many :friends_by_me,
           :through => :friendships_by_me,
           :source => :friendshipped_for_me,
           :conditions => 'accepted_at IS NOT NULL' do
            def online
              find(:all, :conditions => ['status <> ? AND updated_at > ?', 'offline', 65.seconds.ago]) if options[:online_method]
            end
           end
  
  has_many :friends_for_me,
           :through => :friendships_for_me,
           :source => :friendshipped_by_me,
           :conditions => 'accepted_at IS NOT NULL' do
            def online
              find(:all, :conditions => ['status <> ? AND updated_at > ?', 'offline', 65.seconds.ago]) if options[:online_method]
            end
           end
  
  has_many :pending_friends_by_me,
           :through => :friendships_by_me,
           :source => :friendshipped_for_me,
           :conditions => 'accepted_at IS NULL'
  
  has_many :pending_friends_for_me,
           :through => :friendships_for_me,
           :source => :friendshipped_by_me,
           :conditions => 'accepted_at IS NULL'
  
  include HasManyFriends::UserExtensions::InstanceMethods
end