Module: Graphoid::Queries::Processor

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

Class Method Summary collapse

Class Method Details

.execute(scope, object) ⇒ Object



7
8
9
10
# File 'lib/graphoid/queries/processor.rb', line 7

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

.execute_array(scope, list, action) ⇒ Object



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

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



36
37
38
39
# File 'lib/graphoid/queries/processor.rb', line 36

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

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



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

def process(scope, value, key = nil)
  if key && %w[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) && %w[in nin].exclude?(operation&.operator)
      return execute_array(scope, value, key)
    end
  end
end