Module: Mongoid::Criteria::Translator Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
This is a helper module for translating atomic and composite Ruby values into corresponding query and option components. Originally implemented as patches to core classes, that approach has generally fallen into disfavor, as it bleeds too much into the public namespace.
Instance Method Summary collapse
-
#to_direction(value) ⇒ Hash | Numeric
private
Converts the given value to a direction specification for use in sorting.
Instance Method Details
#to_direction(value) ⇒ Hash | Numeric
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the given value to a direction specification for use in sorting.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mongoid/criteria/translator.rb', line 29 def to_direction(value) case value when Hash then value when Numeric then value when String then value =~ /desc/i ? -1 : 1 when Symbol then to_direction(value.to_s) else raise ArgumentError, "cannot translate #{value.inspect} (#{value.class}) to a direction specification" end end |