Class: Toller::Sorts::OrderHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/toller/sorts/order_handler.rb

Overview

Order handler for filter

Instance Method Summary collapse

Instance Method Details

#call(collection, direction, properties) ⇒ ActiveRecord::Relation

Applies a plain order clause to collection for a non-scope sort.

Parameters:

  • collection (ActiveRecord::Relation)

    the collection to sort

  • direction (Symbol)

    the sort direction, :asc or :desc

  • properties (Hash)

    the sort's properties, used to resolve :field

Returns:

  • (ActiveRecord::Relation)

    the sorted collection



16
17
18
19
20
# File 'lib/toller/sorts/order_handler.rb', line 16

def call(collection, direction, properties)
  field_name = properties[:field]

  collection.order(field_name => direction)
end