Module: EloRankable::HasEloRanking

Defined in:
lib/elo_rankable/has_elo_ranking.rb

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#has_elo_rankingObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/elo_rankable/has_elo_ranking.rb', line 5

def has_elo_ranking
  # Set up the polymorphic association
  has_one :elo_ranking, as: :rankable, class_name: 'EloRankable::EloRanking', dependent: :destroy

  # Include instance methods
  include InstanceMethods

  # Add scopes for leaderboards
  scope :by_elo_rating, -> { joins(:elo_ranking).order('elo_rankings.rating DESC') }
  scope :top_rated, ->(limit = 10) { by_elo_rating.limit(limit) }
end