Module: Graphoid::Queries::Processor

Defined in:
lib/graphoid/queries/processor.rb

Class Method Summary collapse

Class Method Details

.children_of(selection) ⇒ Object



34
35
36
# File 'lib/graphoid/queries/processor.rb', line 34

def children_of(selection)
  selection.scoped_children.values[0]
end

.execute(scope, object) ⇒ Object



5
6
7
8
# File 'lib/graphoid/queries/processor.rb', line 5

def execute(scope, object)
  object.each { |key, value| scope = process(scope, value, key) }
  scope
end

.execute_array(scope, list, action) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/graphoid/queries/processor.rb', line 10

def execute_array(scope, list, action)
  if action == "OR"
    scope = Graphoid.driver.execute_or(scope, list)
  else
    list.each { |object| scope = execute(scope, object) }
  end
  scope
end

.parse_order(scope, order) ⇒ Object



38
39
40
41
# File 'lib/graphoid/queries/processor.rb', line 38

def parse_order(scope, order)
  fields = Attribute.fieldnames_of(scope)
  Utils.underscore(order, fields)
end

.process(scope, value, key = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphoid/queries/processor.rb', line 19

def process(scope, value, key = nil)
  if key && ["OR", "AND"].exclude?(key)
    operation = Operation.new(scope, key, value)
    filter = operation.resolve
    return Graphoid.driver.execute_and(scope, filter)
  end

  if operation.nil? || operation.type == :attribute
    return execute(scope, value) if value.is_a?(Hash)
    if value.is_a?(Array) && ["in", "nin"].exclude?(operation&.operator)
      return execute_array(scope, value, key) 
    end
  end
end