Class: RESTFramework::ModelOrderingFilter
- Inherits:
-
BaseFilter
- Object
- BaseFilter
- RESTFramework::ModelOrderingFilter
- Defined in:
- lib/rest_framework/filters.rb
Overview
A filter backend which handles ordering of the recordset.
Instance Method Summary collapse
-
#_get_ordering ⇒ Object
Convert ordering string to an ordering configuration.
- #get_filtered_data(data) ⇒ Object
Methods inherited from BaseFilter
Constructor Details
This class inherits a constructor from RESTFramework::BaseFilter
Instance Method Details
#_get_ordering ⇒ Object
Convert ordering string to an ordering configuration.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rest_framework/filters.rb', line 36 def _get_ordering return nil unless @controller.class.ordering_query_param order_string = @controller.params[@controller.class.ordering_query_param] unless order_string.blank? return order_string.split(',').map { |field| if field[0] == '-' [field[1..-1].to_sym, :desc] else [field.to_sym, :asc] end }.to_h end return nil end |
#get_filtered_data(data) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/rest_framework/filters.rb', line 53 def get_filtered_data(data) ordering = self._get_ordering if ordering && !ordering.empty? return data.order(_get_ordering) end return data end |