Method: ActionBlocks::FilterEngine#process

Defined in:
lib/action_blocks/data_engine/filter_engine.rb

#processObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/action_blocks/data_engine/filter_engine.rb', line 16

def process
  @root_table = @root_klass.arel_table
  @root_key = @root_klass.to_s.underscore.to_sym

  # Add base table to tables
  @tables[@root_key.to_sym] = @root_table

  [@filter_reqs].flatten.each do |matchreq|
    node, *rest = matchreq[:path1]
    # puts "base node: #{node} rest #{rest}"
    base_expression = walk_filter_path(@root_klass, node, @root_key, rest)

    node, *rest = matchreq[:path2]
    # puts "related node: #{node} rest #{rest}"
    related_expression = walk_filter_path(@root_klass, node, @root_key, rest)

    if base_expression.class.ancestors.include?(Arel::Attributes::Attribute)
      where = base_expression.send(matchreq[:predicate], related_expression)
    else
      where = related_expression.send(matchreq[:predicate], base_expression)
    end
    @wheres << where

  end

end