Class: Graphiti::ActiveGraph::Scoping::Internal::SortNormalizer
- Inherits:
-
Object
- Object
- Graphiti::ActiveGraph::Scoping::Internal::SortNormalizer
- Defined in:
- lib/graphiti/active_graph/scoping/internal/sort_normalizer.rb
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
-
#initialize(scope) ⇒ SortNormalizer
constructor
A new instance of SortNormalizer.
- #normalize(includes_hash, sorts, deep_sorts) ⇒ Object
- #normalize_base_sort(sorts) ⇒ Object
- #normalize_deep_sort(includes_hash, sorts) ⇒ Object
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
#scope ⇒ Object (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 |