Class: Might::SortParametersExtractor
- Inherits:
-
Object
- Object
- Might::SortParametersExtractor
- Defined in:
- lib/might/sort_parameters_extractor.rb
Overview
User provided sorting syntax:
* `name` - sort by name
* `-name` - sort by name in reversed order
* `-name,created_at` - sort by name in reversed order, and then sort by created_at
This middleware parses sorting string and builds Parameter array If user passes not defined sort order, it yields to ‘UndefinedParameter`, so you may validate it.
Instance Method Summary collapse
-
#call(env) ⇒ <<Might::RansackableSort::SortParameter, []>]
<<Might::RansackableSort::SortParameter, []>].
-
#initialize(app, parameters_definition) ⇒ SortParametersExtractor
constructor
A new instance of SortParametersExtractor.
Constructor Details
#initialize(app, parameters_definition) ⇒ SortParametersExtractor
Returns a new instance of SortParametersExtractor.
17 18 19 20 |
# File 'lib/might/sort_parameters_extractor.rb', line 17 def initialize(app, parameters_definition) @app = app @parameters_definition = parameters_definition end |
Instance Method Details
#call(env) ⇒ <<Might::RansackableSort::SortParameter, []>]
Returns <<Might::RansackableSort::SortParameter, []>].
27 28 29 30 31 32 33 34 35 |
# File 'lib/might/sort_parameters_extractor.rb', line 27 def call(env) params, errors = env sort_params = sort_order(params[:sort]).map do |(attribute, direction)| extract_parameter(attribute, direction) end app.call([params.merge(sort: sort_params), errors]) end |