module Rankle::ClassMethods
Class methods added to ActiveRecord
models
Public Instance Methods
ranked(name = :default)
click to toggle source
@return [ActiveRecord::Relation]
# File lib/rankle.rb, line 15 def ranked name = :default ranked_results = joins("INNER JOIN rankle_indices ON rankle_indices.indexable_name = '#{name}' AND rankle_indices.indexable_id = #{self.to_s.tableize}.id AND rankle_indices.indexable_type = '#{self.to_s}'") if ranked_results.size == 0 self.all else ranked_results.order('rankle_indices.indexable_position') end end
ranks(strategy)
click to toggle source
# File lib/rankle.rb, line 26 def ranks strategy RankleIndex.ranks self, Ranker.new(strategy) end