lib/leaderboard_factory.rb
def leaderboard board, scope_key, options = {}, redis_options = {}
      self.leaderboard_specs[:instance][board] = {
        key: scope_key,
        options: options,
        redis_options: redis_options
      }

      define_methods board, :instance
    end
# Defines a new leaderboard that will be scoped to some unique property on the object instance.
# Use this if you want to, say, track a specific player's personal bests, or some other
#   stat that is specific to the individual.
# This method defines an accessor that will return the leaderboard, as well as a shorthand
#   method for ranking a new item in the leaderboard
#
# @param board [String] the name of the leaderboard
# @param scope_key [String/Symbol] the name of an attribute on the instance that will scope the leaderboard.
# @param options [Hash] optional; these are passed along to the leaderboard object
# @param redis_options [Hash] optional; these are also passed along to the leaderboard object
#
# Example
#
#    class Player < ActiveRecord::Base
#      include LeaderboardFactory
#      leaderboard 'maps_by_wins', :id
#    end
#
#    p = Player.new(id: 77)
#    p.maps_by_wins # => the player's personal maps leaderboard
#    p.rank_map_by_wins map.name, 33, { map_id: 42 } # => ["OK", true]
Defines a new leaderboard that will be scoped to some unique property on the object instance.
Use this if you want to, say, track a specific player's personal bests, or some other
stat that is specific to the individual.
This method defines an accessor that will return the leaderboard, as well as a shorthand
method for ranking a new item in the leaderboard
Defines a new leaderboard that will be scoped to some unique property on the object instance . Use this if you want to say track a specific player ' s personal bests or some other stat that is specific to the individual . This method defines an accessor that will return the leaderboard as well as a shorthand method for ranking a new item in the leaderboard
def leaderboard board, scope_key, options = {}, redis_options = {}
      self.leaderboard_specs[:instance][board] = {
        key: scope_key,
        options: options,
        redis_options: redis_options
      }
      define_methods board, :instance
    end
def leaderboard board , scope_key , options = { } , redis_options = { } self . leaderboard_specs [ :instance ] [ board ] = { key : scope_key , options : options , redis_options : redis_options } define_methods board , :instance end
Defines a new leaderboard that will be scoped to some unique property on the object instance.
Defines a new leaderboard that will be scoped to some unique property on the object instance .
board
the name of the leaderboard
the name of the leaderboard
scope_key
the name of an attribute on the instance that will scope the leaderboard.
the name of an attribute on the instance that will scope the leaderboard .
options
optional; these are passed along to the leaderboard object
optional ; these are passed along to the leaderboard object
redis_options
optional; these are also passed along to the leaderboard object Example class Player < ActiveRecord::Base include LeaderboardFactory leaderboard 'maps_by_wins', :id end p = Player.new(id: 77) p.maps_by_wins # => the player's personal maps leaderboard p.rank_map_by_wins map.name, 33, { map_id: 42 } # => ["OK", true]
optional ; these are also passed along to the leaderboard object Example class Player < ActiveRecord :: Base include LeaderboardFactory leaderboard ' maps_by_wins ' : id end p = Player . new ( id : 77 ) p . maps_by_wins # = > the player ' s personal maps leaderboard p . rank_map_by_wins map . name 33 { map_id : 42 } # = > [ " OK " true ]