Class: Sunspot::Query::SortComposite
- Inherits:
-
Object
- Object
- Sunspot::Query::SortComposite
- Defined in:
- lib/sunspot/query/sort_composite.rb
Overview
The SortComposite class encapsulates an ordered collection of Sort objects. It’s necessary to keep this as a separate class as Solr takes the sort as a single parameter, so adding sorts as regular components would not merge correctly in the #to_params method.
Instance Method Summary collapse
-
#<<(sort) ⇒ Object
Add a sort to the composite.
-
#initialize ⇒ SortComposite
constructor
:nodoc:.
-
#to_params(prefix = "") ⇒ Object
Combine the sorts into a single param by joining them.
Constructor Details
#initialize ⇒ SortComposite
:nodoc:
10 11 12 |
# File 'lib/sunspot/query/sort_composite.rb', line 10 def initialize @sorts = [] end |
Instance Method Details
#<<(sort) ⇒ Object
Add a sort to the composite
17 18 19 |
# File 'lib/sunspot/query/sort_composite.rb', line 17 def <<(sort) @sorts << sort end |
#to_params(prefix = "") ⇒ Object
Combine the sorts into a single param by joining them
24 25 26 27 28 29 30 31 |
# File 'lib/sunspot/query/sort_composite.rb', line 24 def to_params(prefix = "") unless @sorts.empty? key = "#{prefix}sort".to_sym { key => @sorts.map { |sort| sort.to_param } * ', ' } else {} end end |