Class: ApiMe::Sorting
- Inherits:
-
Object
- Object
- ApiMe::Sorting
- Defined in:
- lib/api_me/sorting.rb
Instance Attribute Summary collapse
-
#custom_sort_options ⇒ Object
Returns the value of attribute custom_sort_options.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#sort_criteria ⇒ Object
Returns the value of attribute sort_criteria.
-
#sort_reverse ⇒ Object
Returns the value of attribute sort_reverse.
Instance Method Summary collapse
-
#initialize(scope:, sort_params:, custom_sort_options: {}) ⇒ Sorting
constructor
A new instance of Sorting.
- #results ⇒ Object
- #sort_meta ⇒ Object
Constructor Details
#initialize(scope:, sort_params:, custom_sort_options: {}) ⇒ Sorting
Returns a new instance of Sorting.
7 8 9 10 11 12 13 14 15 |
# File 'lib/api_me/sorting.rb', line 7 def initialize(scope:, sort_params:, custom_sort_options: {}) self.scope = scope return unless sort_params self.sort_criteria = sort_params[:criteria] || default_sort_criteria self.sort_reverse = sort_params[:reverse] || false self. = end |
Instance Attribute Details
#custom_sort_options ⇒ Object
Returns the value of attribute custom_sort_options.
5 6 7 |
# File 'lib/api_me/sorting.rb', line 5 def @custom_sort_options end |
#scope ⇒ Object
Returns the value of attribute scope.
5 6 7 |
# File 'lib/api_me/sorting.rb', line 5 def scope @scope end |
#sort_criteria ⇒ Object
Returns the value of attribute sort_criteria.
5 6 7 |
# File 'lib/api_me/sorting.rb', line 5 def sort_criteria @sort_criteria end |
#sort_reverse ⇒ Object
Returns the value of attribute sort_reverse.
5 6 7 |
# File 'lib/api_me/sorting.rb', line 5 def sort_reverse @sort_reverse end |
Instance Method Details
#results ⇒ Object
17 18 19 |
# File 'lib/api_me/sorting.rb', line 17 def results sorting? ? sort(sort_criteria).scope : scope end |
#sort_meta ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/api_me/sorting.rb', line 21 def return {} unless sorting? { criteria: , reverse: sort_reverse } end |