Module: Likeable::Facepile

Defined in:
lib/likeable/facepile.rb

Instance Method Summary collapse

Instance Method Details

#ids_for_facepile(user, limit = Likeable.facepile_default_limit) ⇒ Object


14
15
16
17
# File 'lib/likeable/facepile.rb', line 14

def ids_for_facepile(user, limit = Likeable.facepile_default_limit)
  ids = liked_friend_ids(user).shuffle + like_user_ids.shuffle # show friends first
  ids.uniq.first(limit)
end

#liked_friend_ids(user) ⇒ Object


10
11
12
# File 'lib/likeable/facepile.rb', line 10

def liked_friend_ids(user)
  @liked_friend_ids ||= like_user_ids & user.friend_ids
end

#liked_friends(user, limit = nil) ⇒ Object

returns friend of user who like target


4
5
6
7
8
# File 'lib/likeable/facepile.rb', line 4

def liked_friends(user, limit = nil)
  friend_ids = liked_friend_ids(user)
  friend_ids = friend_ids.sample(limit) unless limit.blank?
  @liked_friends ||= Likeable.find_many(User, friend_ids)
end

#users_for_facepile(user, limit = Likeable.facepile_default_limit) ⇒ Object


19
20
21
22
23
24
25
# File 'lib/likeable/facepile.rb', line 19

def users_for_facepile(user, limit = Likeable.facepile_default_limit)
  return [] if user.blank?
  @facepile ||= begin
    return nil unless ids = ids_for_facepile(user, limit)
    Likeable.find_many(User, ids)
  end
end