Module: ActiveGraphExtensions::Node::Query::QueryProxyEagerLoading::EagerLoadingOrder

Included in:
ActiveGraphExtensions::Node::Query::QueryProxyEagerLoading
Defined in:
lib/active_graph_extensions/node/query/query_proxy_eager_loading/eager_loading_order.rb

Overview

Used to append auth scopes to query proxy eagerloading

Instance Method Summary collapse

Instance Method Details

#nested_order_clause(node_alias, order_spec) ⇒ Object



25
26
27
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/eager_loading_order.rb', line 25

def nested_order_clause(node_alias, order_spec)
  [node_or_rel_alias(node_alias, order_spec), name(order_spec)].join('.')
end

#optional_order(query, path, previous_with_vars) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/eager_loading_order.rb', line 9

def optional_order(query, path, previous_with_vars)
  node_alias = path_name(path)
  order_clause = order_clause_for_query(node_alias)
  if path.last.rel_length
    order_clause.reject! { |el| el.include?('_rel') }
    query.order("length(`#{node_alias}_path`)", *order_clause)
         .with(*with_variables(path, node_alias, previous_with_vars))
  else
    query.order(*order_clause).with(*with_variables(path, node_alias, previous_with_vars))
  end
end

#order_clause(key, order_spec) ⇒ Object



29
30
31
32
33
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/eager_loading_order.rb', line 29

def order_clause(key, order_spec)
  property_with_direction = name(order_spec)
  node_alias = node_aliase_for_collection(key, order_spec) || node_aliase_for_order(property_with_direction)
  [node_alias, property_with_direction].compact.join('.')
end

#order_clause_for_query(node_alias) ⇒ Object



21
22
23
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/eager_loading_order.rb', line 21

def order_clause_for_query(node_alias)
  (order = @order_spec&.fetch(node_alias, nil)) ? order.map(&method(:nested_order_clause).curry.call(node_alias)) : []
end

#skip_order?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/eager_loading_order.rb', line 35

def skip_order?
  @order_spec.blank? || @order_spec.keys.all?(&:blank?)
end