Class: RESTFramework::Filters::BaseFilter
- Inherits:
-
Object
- Object
- RESTFramework::Filters::BaseFilter
- Defined in:
- lib/rest_framework/filters/base_filter.rb
Direct Known Subclasses
Class Method Summary collapse
-
._safe_query_value?(v) ⇒ Boolean
True when
vis a query-parameter value safe to feed intowhere, string operations, orsplit— i.e.
Instance Method Summary collapse
-
#_polymorphic_columns(custom_fields) ⇒ Object
The controller's polymorphic
<assoc>.id/<assoc>.type→ backing-column map, gated by a custom field allowlist when the subclass defines one (filter_fields/ordering_fields). - #filter_data(data) ⇒ Object
-
#initialize(controller:) ⇒ BaseFilter
constructor
A new instance of BaseFilter.
Constructor Details
#initialize(controller:) ⇒ BaseFilter
Returns a new instance of BaseFilter.
2 3 4 |
# File 'lib/rest_framework/filters/base_filter.rb', line 2 def initialize(controller:) @controller = controller end |
Class Method Details
._safe_query_value?(v) ⇒ Boolean
True when v is a query-parameter value safe to feed into where, string
operations, or split — i.e. a String or an Array of Strings. Guards against
nested-hash inputs like ?field[evil]=x, which Rack parses into a Hash and
which AR cannot quote as a bind.
24 25 26 27 28 |
# File 'lib/rest_framework/filters/base_filter.rb', line 24 def self._safe_query_value?(v) return true if v.is_a?(String) return v.all? { |el| el.is_a?(String) } if v.is_a?(Array) false end |
Instance Method Details
#_polymorphic_columns(custom_fields) ⇒ Object
The controller's polymorphic <assoc>.id/<assoc>.type → backing-column map, gated by a custom
field allowlist when the subclass defines one (filter_fields/ordering_fields). This keeps a
restricted allowlist restrictive: a polymorphic path is honored only if it is also listed there.
13 14 15 16 17 18 |
# File 'lib/rest_framework/filters/base_filter.rb', line 13 def _polymorphic_columns(custom_fields) map = @controller.readable_polymorphic_columns return map unless custom_fields map.slice(*custom_fields.map(&:to_s)) end |
#filter_data(data) ⇒ Object
6 7 8 |
# File 'lib/rest_framework/filters/base_filter.rb', line 6 def filter_data(data) raise NotImplementedError end |