Module: Recommendable::Ratable::Likable

Defined in:
lib/recommendable/ratable/likable.rb

Instance Method Summary collapse

Instance Method Details

#liked_byArray

Fetch a list of users that have liked this item.

Returns:

  • (Array)

    a list of users that have liked this item



7
8
9
# File 'lib/recommendable/ratable/likable.rb', line 7

def liked_by
  Recommendable.query(Recommendable.config.user_class, liked_by_ids)
end

#liked_by_countFixnum

Get the number of users that have liked this item

Returns:

  • (Fixnum)

    the number of users that have liked this item



14
15
16
# File 'lib/recommendable/ratable/likable.rb', line 14

def liked_by_count
  Recommendable.redis.scard(Recommendable::Helpers::RedisKeyMapper.liked_by_set_for(self.class, id))
end

#liked_by_idsArray

Get the IDs of users that have liked this item.

Returns:

  • (Array)

    the IDs of users that have liked this item



21
22
23
# File 'lib/recommendable/ratable/likable.rb', line 21

def liked_by_ids
  Recommendable.redis.smembers(Recommendable::Helpers::RedisKeyMapper.liked_by_set_for(self.class, id))
end