Class: Graphiti::ActiveGraph::Scoping::Internal::SortNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/active_graph/scoping/internal/sort_normalizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ SortNormalizer

Returns a new instance of SortNormalizer.



7
8
9
# File 'lib/graphiti/active_graph/scoping/internal/sort_normalizer.rb', line 7

def initialize(scope)
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



5
6
7
# File 'lib/graphiti/active_graph/scoping/internal/sort_normalizer.rb', line 5

def scope
  @scope
end

Instance Method Details

#normalize(includes_hash, sorts, deep_sorts) ⇒ Object



11
12
13
14
15
# File 'lib/graphiti/active_graph/scoping/internal/sort_normalizer.rb', line 11

def normalize(includes_hash, sorts, deep_sorts)
  normalized_deep_sort = normalize_deep_sort(includes_hash, deep_sorts || [])
  normalized_base_sort = normalize_base_sort(sorts)
  normalized_deep_sort.merge(normalized_base_sort)
end

#normalize_base_sort(sorts) ⇒ Object



17
18
19
# File 'lib/graphiti/active_graph/scoping/internal/sort_normalizer.rb', line 17

def normalize_base_sort(sorts)
  sorts.present? ? { '' => sorts.map { |sort| "#{sort.keys.first} #{sort.values.first}" } } : {}
end

#normalize_deep_sort(includes_hash, sorts) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/graphiti/active_graph/scoping/internal/sort_normalizer.rb', line 21

def normalize_deep_sort(includes_hash, sorts)
  sorts
    .map { |sort| sort(includes_hash, sort) }
    .compact
    .group_by(&:first)
    .map { |key, value| combined_order_spec(key, value) }
    .to_h
end