Module: Mongoid::SleepingKingStudios::Orderable::ClassMethods
- Defined in:
- lib/mongoid/sleeping_king_studios/orderable.rb
Overview
Class methods added to the base class via #extend.
Instance Method Summary collapse
-
#cache_ordering(sort_params, options = {}) ⇒ Object
Creates the order field and sets up the callbacks and helpers.
-
#first_ordering_name ⇒ Mongoid::Document?
Finds the first document, based on the stored ordering values.
-
#last_ordering_name ⇒ Mongoid::Document?
Finds the last document, based on the stored ordering values.
-
#reorder_ordering_name! ⇒ Object
Iterates through the entire collection and sets the cached order of each item to its current order index.
Instance Method Details
#cache_ordering(sort_params, options = {}) ⇒ Object
188 189 190 191 |
# File 'lib/mongoid/sleeping_king_studios/orderable.rb', line 188 def cache_ordering *sort_params, ** concern = Mongoid::SleepingKingStudios::Orderable concern.apply self, sort_params, end |
#first_ordering_name ⇒ Mongoid::Document?
Finds the first document, based on the stored ordering values.
The generated name of this method will depend on the sort params or the :as option provided. For example, :as => :alphabetical_order will result in an instance method #first_alphabetical.
|
# File 'lib/mongoid/sleeping_king_studios/orderable.rb', line 193
|
#last_ordering_name ⇒ Mongoid::Document?
Finds the last document, based on the stored ordering values.
The generated name of this method will depend on the sort params or the :as option provided. For example, :as => :alphabetical_order will result in an instance method #last_alphabetical.
|
# File 'lib/mongoid/sleeping_king_studios/orderable.rb', line 203
|
#reorder_ordering_name! ⇒ Object
Iterates through the entire collection and sets the cached order of each item to its current order index. Filtered items have their order set to nil. Normally, this should be taken care of when the items are saved, but this method allows the process to be reset in case of data corruption or other issues.
The generated name of this method will depend on the sort params or the :as option provided. For example, :as => :alphabetical_order will result in a class method ::reorder_alphabetical!.
|
# File 'lib/mongoid/sleeping_king_studios/orderable.rb', line 213
|