Module: Lexorank::Rankable::ClassMethods
- Defined in:
- lib/lexorank/rankable.rb
Instance Attribute Summary collapse
-
#lexorank_ranking ⇒ Object
readonly
Returns the value of attribute lexorank_ranking.
Instance Method Summary collapse
Instance Attribute Details
#lexorank_ranking ⇒ Object (readonly)
Returns the value of attribute lexorank_ranking.
11 12 13 |
# File 'lib/lexorank/rankable.rb', line 11 def lexorank_ranking @lexorank_ranking end |
Instance Method Details
#rank!(field: :rank, group_by: nil, advisory_lock: {}) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/lexorank/rankable.rb', line 13 def rank!(field: :rank, group_by: nil, advisory_lock: {}) @lexorank_ranking = Lexorank::Ranking.new(record_class: self, field: field, group_by: group_by, advisory_lock: advisory_lock) lexorank_ranking.validate! if lexorank_ranking.field scope :ranked, ->(direction: :asc) { where.not("#{lexorank_ranking.field}": nil).order("#{lexorank_ranking.field}": direction) } include InstanceMethods end end |