Class: RESTFramework::ModelFilter
- Inherits:
-
BaseFilter
- Object
- BaseFilter
- RESTFramework::ModelFilter
- Defined in:
- lib/rest_framework/filters.rb
Overview
A simple filtering backend that supports filtering a recordset based on fields defined on the controller class.
Instance Method Summary collapse
-
#_get_filter_params ⇒ Object
Filter params for keys allowed by the current action’s filterset_fields/fields config.
-
#get_filtered_data(data) ⇒ Object
Filter data according to the request query parameters.
Methods inherited from BaseFilter
Constructor Details
This class inherits a constructor from RESTFramework::BaseFilter
Instance Method Details
#_get_filter_params ⇒ Object
Filter params for keys allowed by the current action’s filterset_fields/fields config.
15 16 17 18 19 20 21 22 |
# File 'lib/rest_framework/filters.rb', line 15 def _get_filter_params # Map filterset fields to strings because query parameter keys are strings. if fields = @controller.get_filterset_fields&.map(&:to_s) return @controller.request.query_parameters.select { |p, _| fields.include?(p) } end return @controller.request.query_parameters.to_h end |
#get_filtered_data(data) ⇒ Object
Filter data according to the request query parameters.
25 26 27 28 29 30 31 32 |
# File 'lib/rest_framework/filters.rb', line 25 def get_filtered_data(data) filter_params = self._get_filter_params.symbolize_keys unless filter_params.blank? return data.where(**filter_params) end return data end |