Module: Cuprum::Collections::Queries::Ordering
- Defined in:
- lib/cuprum/collections/queries/ordering.rb
Overview
Functionality around validating and normalizing query sort orderings.
Defined Under Namespace
Classes: InvalidOrderError
Class Method Summary collapse
-
.normalize(*attributes, ordering_hash = nil) ⇒ Hash
Converts the given sort order into a hash with standard values.
Class Method Details
.normalize(*attributes, ordering_hash = nil) ⇒ Hash
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cuprum/collections/queries/ordering.rb', line 35 def normalize(*attributes) attributes = attributes.flatten if attributes.first.is_a?(Array) validate_ordering!(attributes) qualified = attributes.last.is_a?(Hash) ? attributes.pop : {} qualified = normalize_order_hash(qualified) attributes .each .with_object({}) { |attribute, hsh| hsh[attribute.intern] = :asc } .merge(qualified) end |