Class: SimpleCrud::Pagination::PagyAdapter
- Inherits:
-
Object
- Object
- SimpleCrud::Pagination::PagyAdapter
- Includes:
- Adapter
- Defined in:
- lib/simple_crud/pagination/pagy_adapter.rb
Overview
Assumes the controller includes Pagy::Method.
Constant Summary collapse
- MAX_LIMIT_KEY =
43.5.0 renamed client_max_limit -> max_limit. Ruby < 3.3 resolves to the pre-rename 43.4.x, so pick whichever key the loaded Pagy expects.
Gem::Version.new(Pagy::VERSION) >= Gem::Version.new('43.5.0') ? :max_limit : :client_max_limit
Instance Method Summary collapse
- #paginate(controller, relation, options) ⇒ Object
- #paginated_records(controller, relation, _options) ⇒ Object
Instance Method Details
#paginate(controller, relation, options) ⇒ Object
16 17 18 19 |
# File 'lib/simple_crud/pagination/pagy_adapter.rb', line 16 def paginate(controller, relation, ) records = paginated_records(controller, relation, ) controller.render({ json: records }.merge()) end |
#paginated_records(controller, relation, _options) ⇒ Object
21 22 23 24 |
# File 'lib/simple_crud/pagination/pagy_adapter.rb', line 21 def paginated_records(controller, relation, ) _pagy, records = controller.send(:pagy, relation, MAX_LIMIT_KEY => 100) records end |