Class: RailsExecution::Services::Paging
- Inherits:
-
Object
- Object
- RailsExecution::Services::Paging
- Defined in:
- lib/rails_execution/services/paging.rb
Instance Method Summary collapse
- #call(relation) ⇒ Object
-
#initialize(per_page: nil, page: 1) ⇒ Paging
constructor
A new instance of Paging.
Constructor Details
#initialize(per_page: nil, page: 1) ⇒ Paging
Returns a new instance of Paging.
5 6 7 8 9 |
# File 'lib/rails_execution/services/paging.rb', line 5 def initialize(per_page: nil, page: 1) @per_page = per_page.presence || RailsExecution.configuration.per_page.to_i @per_page = [@per_page, 1].max @page = [page.to_i, 1].max end |
Instance Method Details
#call(relation) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/rails_execution/services/paging.rb', line 11 def call(relation) total_count = relation.count relation = relation.offset(offset_paging).limit(per_page) inject_paging_data(relation, total_count) return relation end |