Module: Positionable
- Defined in:
- lib/positionable.rb,
lib/positionable/version.rb
Overview
Positionable is a library which provides contiguous positionning capabilities to your ActiveRecord models. This module is designed to be an ActiveRecord extension.
Calling the is_positionable method in your ActiveRecord model will inject positionning capabilities. In particular, this will guarantee your records’ positions to be contiguous, ie.: there is no ‘hole’ between two adjacent positions.
Positionable has a strong management of records that belong to a group (a.k.a. scope). When a record is moved whithin its scope, or from a scope to another, other impacted records are also reordered accordingly.
You can use the provided instance methods (up!, down! or move_to) to move or reorder your records, whereas it is possible to update the position via mass-assignement. In particular, update_attributes({:position => new_position}) will trigger some ActiveRecord callbacks in order to maintain positions’ contiguity.
Additional methods are available to query your model: check if this the last? or first? of its own scope, retrieve the previous or the next records according to their positions, etc.
Defined Under Namespace
Modules: PositionableMethods Classes: RangeWithoutScopeError
Constant Summary collapse
- VERSION =
"1.0.7"
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
25 26 27 |
# File 'lib/positionable.rb', line 25 def self.included(base) base.extend(PositionableMethods) end |