Module: DynamicSunspotSearch::Translator::OrderBy

Defined in:
lib/dynamic_sunspot_search/translator/order_by.rb

Class Method Summary collapse

Class Method Details

.apply(query_object, order_by) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dynamic_sunspot_search/translator/order_by.rb', line 4

def self.apply(query_object, order_by)
  return unless order_by.present?
  query_object.tap do |search|
    Array.wrap(order_by).each do |order_options|
      case order_options
      when Hash
        field, direction = order_options.first
        search.order_by(field, direction)
      when Symbol, String
        search.order_by(order_options)
      else
        raise NotImplementedError
      end
    end
  end
end