class Toller::Sort

Sort

Attributes

parameter[R]
properties[R]
type[R]

Public Class Methods

new(parameter, type, options) click to toggle source
# File lib/toller/sort.rb, line 10
def initialize(parameter, type, options)
  @parameter = parameter
  @type = type
  @properties = options.reverse_merge(
    field: parameter,
    default: false,
    scope_name: nil
  )
end

Public Instance Methods

apply!(collection, direction = :asc) click to toggle source
# File lib/toller/sort.rb, line 20
def apply!(collection, direction = :asc)
  if type == :scope
    Sorts::ScopeHandler.new.call(collection, direction, properties)
  else
    Sorts::OrderHandler.new.call(collection, direction, properties)
  end
end
default() click to toggle source
# File lib/toller/sort.rb, line 28
def default
  properties[:default]
end