lib/recommendable/rater/liker.rb in recommendable-2.2.0 vs lib/recommendable/rater/liker.rb in recommendable-2.2.1
- old
+ new
@@ -63,57 +63,50 @@
Recommendable.config.ratable_classes.inject(0) do |sum, klass|
sum + liked_count_for(klass)
end
end
- private
-
# Fetch IDs for objects belonging to a passed class that the user has liked
#
# @param [String, Symbol, Class] the class for which you want IDs
# @return [Array] an array of IDs
- # @private
def liked_ids_for(klass)
ids = Recommendable.redis.smembers(Recommendable::Helpers::RedisKeyMapper.liked_set_for(klass, id))
ids.map!(&:to_i) if [:active_record, :data_mapper, :sequel].include?(Recommendable.config.orm)
ids
end
# Fetch records belonging to a passed class that the user has liked
#
# @param [String, Symbol, Class] the class for which you want liked records
# @return [Array] an array of liked records
- # @private
def liked_for(klass)
Recommendable.query(klass, liked_ids_for(klass))
end
# Get the number of items belonging to a passed class that the user has liked
#
# @param [String, Symbol, Class] the class for which you want a count of likes
# @return [Fixnum] the number of likes
- # @private
def liked_count_for(klass)
Recommendable.redis.scard(Recommendable::Helpers::RedisKeyMapper.liked_set_for(klass, id))
end
# Get a list of records that both this user and a passed user have liked
#
# @param [User] the other user
# @param [String, Symbol, Class] the class of common liked items
# @return [Array] an array of records both users have liked
- # @private
def liked_in_common_with(klass, user)
Recommendable.query(klass, liked_ids_in_common_with(klass, user))
end
# Get a list of IDs for records that both this user and a passed user have
# liked
#
# @param [User, Fixnum] the other user (or its ID)
# @param [String, Symbol, Class] the class of common liked items
# @return [Array] an array of IDs for records that both users have liked
- # @private
def liked_ids_in_common_with(klass, user_id)
user_id = user_id.id if user_id.is_a?(Recommendable.config.user_class)
Recommendable.redis.sinter(Recommendable::Helpers::RedisKeyMapper.liked_set_for(klass, id), Recommendable::Helpers::RedisKeyMapper.liked_set_for(klass, user_id))
end
end