module Orderable2

Constants

VERSION

Public Instance Methods

sort_order(order = nil) click to toggle source
# File lib/orderable2.rb, line 6
def sort_order(order = nil)
  calculate_order(order)
end

Private Instance Methods

calculate_order(default_order = nil) click to toggle source
# File lib/orderable2.rb, line 12
def calculate_order(default_order = nil)
  if params[:order]
    params[:order].split(',').map do |stmt|
      stmt_array = stmt.split(':')
      { stmt_array.first.to_sym => stmt_array.last.to_sym }
    end.reduce({}, :merge)
  else
    default_order || { id: :asc }
  end
end