Class: Mincer::Processors::Sorting::Processor
- Inherits:
-
Object
- Object
- Mincer::Processors::Sorting::Processor
- Defined in:
- lib/mincer/processors/sorting/processor.rb
Instance Method Summary collapse
- #apply ⇒ Object
- #default_order ⇒ Object
- #default_sort ⇒ Object
-
#initialize(mincer) ⇒ Processor
constructor
A new instance of Processor.
- #order ⇒ Object
- #order_attr ⇒ Object
- #sort ⇒ Object
- #sort_attr ⇒ Object
- #sort_string ⇒ Object
Constructor Details
#initialize(mincer) ⇒ Processor
Returns a new instance of Processor.
5 6 7 |
# File 'lib/mincer/processors/sorting/processor.rb', line 5 def initialize(mincer) @mincer, @args, @relation = mincer, mincer.args, mincer.relation end |
Instance Method Details
#apply ⇒ Object
9 10 11 12 13 |
# File 'lib/mincer/processors/sorting/processor.rb', line 9 def apply relation = @relation.order(sort_string) @mincer.sort_attribute, @mincer.sort_order = sort_attr, order_attr relation end |
#default_order ⇒ Object
43 44 45 |
# File 'lib/mincer/processors/sorting/processor.rb', line 43 def default_order @mincer.try(:default_sort_order) end |
#default_sort ⇒ Object
35 36 37 |
# File 'lib/mincer/processors/sorting/processor.rb', line 35 def default_sort @mincer.try(:default_sort_attribute) end |
#order ⇒ Object
39 40 41 |
# File 'lib/mincer/processors/sorting/processor.rb', line 39 def order @args[::Mincer.config.sorting.order_param_name] end |
#order_attr ⇒ Object
27 28 29 |
# File 'lib/mincer/processors/sorting/processor.rb', line 27 def order_attr %w{asc desc}.include?(order.try(:downcase)) && order end |
#sort ⇒ Object
31 32 33 |
# File 'lib/mincer/processors/sorting/processor.rb', line 31 def sort @args[::Mincer.config.sorting.sort_param_name] end |
#sort_attr ⇒ Object
23 24 25 |
# File 'lib/mincer/processors/sorting/processor.rb', line 23 def sort_attr @mincer.send(:allowed_sort_attributes).include?(sort) && sort end |
#sort_string ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/mincer/processors/sorting/processor.rb', line 15 def sort_string if sort_attr "#{sort_attr} #{order_attr || default_order}" else "#{default_sort} #{order_attr || default_order}" end end |