Module: JSONAPI::Utils::Support::Filter
- Defined in:
- lib/jsonapi/utils/support/filter.rb,
lib/jsonapi/utils/support/filter/custom.rb,
lib/jsonapi/utils/support/filter/default.rb
Defined Under Namespace
Instance Method Summary collapse
- #apply_filter(records, options = {}) ⇒ Object
- #apply_filter?(records, options = {}) ⇒ Boolean
- #filter_params ⇒ Object
Instance Method Details
#apply_filter(records, options = {}) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/jsonapi/utils/support/filter.rb', line 5 def apply_filter(records, = {}) if apply_filter?(records, ) records.where(filter_params) else records end end |
#apply_filter?(records, options = {}) ⇒ Boolean
13 14 15 16 |
# File 'lib/jsonapi/utils/support/filter.rb', line 13 def apply_filter?(records, = {}) params[:filter].present? && records.respond_to?(:where) && ([:filter].nil? || [:filter]) end |
#filter_params ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jsonapi/utils/support/filter.rb', line 18 def filter_params @_filter_params ||= case params[:filter] when Hash, ActionController::Parameters default_filters.each_with_object({}) do |field, hash| unformatted_field = @request.unformat_key(field) hash[unformatted_field] = params[:filter][field] end end end |