Method: Katalyst::Tables::Collection::Sorting::Sort#call

Defined in:
app/models/concerns/katalyst/tables/collection/sorting.rb

#call(collection) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/concerns/katalyst/tables/collection/sorting.rb', line 120

def call(collection)
  collection = @app.call(collection)

  column, direction = collection.sort.to_h.values_at(:column, :direction)

  return collection if column.nil?

  if collection.items.respond_to?(:"order_by_#{column}")
    collection.items = collection.items.reorder(nil).public_send(:"order_by_#{column}", direction.to_sym)
  elsif collection.model.has_attribute?(column)
    collection.items = collection.items.reorder(column => direction)
  end

  collection
end