ActsAsRrranking

Build Status Gem Version Code Climate

A rails plugin use redis to sort models on real time.

Example

class Player < ActiveRecord::Base
  acts_as_rrranking :ranking, score: :game_point
end

Arguments

name

the name of the ranking field

options

scorethe field which the models can be sorted by (default: :score)
idthe identification field of the models (default: :id)

Helper Methods

Suppose the name is :ranking and the score field is :game_point then the following methods will be generated:

#current_rankingreturn the current ranking
#update_ranking(score)update the score to redis, also will be invoked in the after_save hook
::top_rankings(limit, offset)return the array of top ids
::top_ranking_player(limit, offset)return the array of top models