Module: NoBrainer::Criteria::OrderBy
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/no_brainer/criteria/order_by.rb
Defined Under Namespace
Classes: IndexFinder
Instance Method Summary collapse
- #order_by(*rules, &block) ⇒ Object (also: #order)
- #order_by_index_name ⇒ Object
- #order_by_indexed? ⇒ Boolean
- #reverse_order ⇒ Object
- #without_ordering ⇒ Object
Instance Method Details
#order_by(*rules, &block) ⇒ Object Also known as: order
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/no_brainer/criteria/order_by.rb', line 8 def order_by(*rules, &block) # Note: We are relying on the fact that Hashes are ordered (since 1.9) rules = [*rules, block].flatten.compact.map do |rule| case rule when Hash then bad_rule = rule.values.reject { |v| v.in? [:asc, :desc] }.first raise_bad_rule(bad_rule) if bad_rule rule when String, Symbol, Proc then { rule => :asc } else raise_bad_rule(rule) end end.reduce({}, :merge) rules.keys.each { |k| model.ensure_valid_key!(k) unless k.is_a?(Proc) } if model chain(:order_by => rules, :ordering_mode => :explicit, :reversed_ordering => false) end |
#order_by_index_name ⇒ Object
41 42 43 |
# File 'lib/no_brainer/criteria/order_by.rb', line 41 def order_by_index_name order_by_index_finder.index_name end |
#order_by_indexed? ⇒ Boolean
37 38 39 |
# File 'lib/no_brainer/criteria/order_by.rb', line 37 def order_by_indexed? !!order_by_index_name end |
#reverse_order ⇒ Object
33 34 35 |
# File 'lib/no_brainer/criteria/order_by.rb', line 33 def reverse_order chain(:reversed_ordering => !@options[:reversed_ordering]) end |
#without_ordering ⇒ Object
29 30 31 |
# File 'lib/no_brainer/criteria/order_by.rb', line 29 def without_ordering chain(:ordering_mode => :disabled) end |