Module: Rankle::ClassMethods
- Defined in:
- lib/rankle.rb
Overview
Class methods added to ActiveRecord models
Instance Method Summary collapse
Instance Method Details
#ranked(name = :default) ⇒ ActiveRecord::Relation
15 16 17 18 19 20 21 22 23 24 |
# 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) ⇒ Object
26 27 28 |
# File 'lib/rankle.rb', line 26 def ranks strategy RankleIndex.ranks self, Ranker.new(strategy) end |