module Resort::Sortable
The module encapsulating all the Resort
functionality.
@todo Refactor into a more OO solution, maybe implementing a LinkedList
object.
Public Class Methods
included(base)
click to toggle source
When included, extends the includer with {ClassMethods}, and includes {InstanceMethods} in it.
It also establishes the required relationships. It is necessary that the includer table has the following database columns:
t.references :next t.boolean :first
@param [ActiveRecord::Base] base the includer ‘ActiveRecord` model.
# File lib/resort.rb, line 59 def included(base) base.extend ClassMethods base.send :include, InstanceMethods base.has_one :previous, :class_name => base.name, :foreign_key => 'next_id', :inverse_of => :next base.belongs_to :next, :class_name => base.name, :inverse_of => :previous base.after_create :include_in_list! base.after_destroy :delete_from_list end