Module: JSONAPI::Filtering

Defined in:
lib/jsonapi/filtering.rb

Class Method Summary collapse

Class Method Details

.extract_attributes_and_predicates(requested_field) ⇒ Array

Parses and returns the attribute and the predicate of a ransack field

Parameters:

  • requested_field (String)

    the field to parse

Returns:

  • (Array)

    with the fields and the predicate



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jsonapi/filtering.rb', line 14

def self.extract_attributes_and_predicates(requested_field)
  predicates = []
  field_name = requested_field.to_s.dup

  while Ransack::Predicate.detect_from_string(field_name).present? do
    predicate = Ransack::Predicate
      .detect_and_strip_from_string!(field_name)
    predicates << Ransack::Predicate.named(predicate)
  end

  [field_name.split(/_and_|_or_/), predicates.reverse]
end