Module: Pacecar::Ranking::ClassMethods

Defined in:
lib/pacecar/ranking.rb

Instance Method Summary collapse

Instance Method Details

#has_calculated_records(*names) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pacecar/ranking.rb', line 14

def has_calculated_records(*names)
  opts = names.extract_options!
  names.each do |association_name|
    *columns = opts[:on] || []
    columns.flatten.each do |column|
      define_calculated_scope association_name, column, :average, :avg
      define_calculated_scope association_name, column, :total, :sum
      define_calculated_scope association_name, column, :count, :count
    end
  end
end

#has_ranking(association) ⇒ Object



9
10
11
12
# File 'lib/pacecar/ranking.rb', line 9

def has_ranking(association)
  define_ranking_scope association, :maximum, :desc
  define_ranking_scope association, :minimum, :asc
end