Module: SimpleListing::Sortable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Standard
- Defined in:
- lib/simple_listing/sortable.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- SORT_DIRECTIONS =
%w{asc desc}.freeze
Instance Method Summary collapse
- #inverted_sort_direction ⇒ Object
- #perform ⇒ Object
- #should_be_sorted? ⇒ Boolean
- #sort_direction ⇒ Object
- #sort_value ⇒ Object
Instance Method Details
#inverted_sort_direction ⇒ Object
50 51 52 |
# File 'lib/simple_listing/sortable.rb', line 50 def inverted_sort_direction sort_direction == :asc ? :desc : :asc end |
#perform ⇒ Object
30 31 32 33 34 |
# File 'lib/simple_listing/sortable.rb', line 30 def perform super apply_sorting if should_be_sorted? scope end |
#should_be_sorted? ⇒ Boolean
54 55 56 |
# File 'lib/simple_listing/sortable.rb', line 54 def should_be_sorted? params[config[:sort_by_param_key]] && params[config[:sort_direction_param_key]] end |
#sort_direction ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/simple_listing/sortable.rb', line 42 def sort_direction @sort_direction ||= begin direction = params[config[:sort_direction_param_key]] guard("incorrect sorting direction '#{direction}'") { direction.in? SORT_DIRECTIONS } direction.to_sym end end |
#sort_value ⇒ Object
36 37 38 39 40 |
# File 'lib/simple_listing/sortable.rb', line 36 def sort_value @sort_value ||= params[config[:sort_by_param_key]].tap do |value| guard("incorrect sorting value '#{value}'") { sortable_by?(value) } end end |