Method: Ransack::Nodes::Condition.extract

Defined in:
lib/ransack/nodes/condition.rb

.extract(context, key, values) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ransack/nodes/condition.rb', line 11

def extract(context, key, values)
  attributes, predicate, combinator =
    extract_values_for_condition(key, context)

  if attributes.size > 0 && predicate
    condition = self.new(context)
    condition.build(
      a: attributes,
      p: predicate.name,
      m: combinator,
      v: predicate.wants_array ? Array(values) : [values]
    )
    # TODO: Figure out what to do with multiple types of attributes,
    # if anything. Tempted to go with "garbage in, garbage out" here.
    if predicate.validate(condition.values, condition.default_type)
      condition
    else
      nil
    end
  end
end