Class: Might::SortMiddleware
- Inherits:
-
Object
- Object
- Might::SortMiddleware
- Defined in:
- lib/might/sort_middleware.rb
Overview
Sort scope using ransack gem
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
-
#call(env) ⇒ Object
First argument is a ActiveRecord relation which must be sorted Second argument is a request parameters provided by user.
-
#initialize(app) ⇒ SortMiddleware
constructor
A new instance of SortMiddleware.
Constructor Details
#initialize(app) ⇒ SortMiddleware
Returns a new instance of SortMiddleware.
8 9 10 |
# File 'lib/might/sort_middleware.rb', line 8 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
12 13 14 |
# File 'lib/might/sort_middleware.rb', line 12 def app @app end |
Instance Method Details
#call(env) ⇒ Object
First argument is a ActiveRecord relation which must be sorted Second argument is a request parameters provided by user
18 19 20 21 22 23 24 25 |
# File 'lib/might/sort_middleware.rb', line 18 def call(env) scope, = ::Middleware::Builder.new do |b| b.use RansackableSortParametersAdapter b.use RansackableSort end.call(env) app.call([scope, env[1]]) end |