Class: Wallaby::ActiveRecord::ModelPaginationProvider
- Inherits:
-
ModelPaginationProvider
- Object
- ModelPaginationProvider
- Wallaby::ActiveRecord::ModelPaginationProvider
- Defined in:
- lib/adapters/wallaby/active_record/model_pagination_provider.rb
Overview
Model pagination provider for Wallaby::ActiveRecord
Instance Method Summary collapse
-
#page_number ⇒ Integer
Page number from parameters starting from 1.
-
#page_size ⇒ Integer
Page size from parameters or Wallaby configuration.
-
#paginatable? ⇒ true, false
Check if collection can be paginated.
-
#total ⇒ Integer
Total count for the collection.
Instance Method Details
#page_number ⇒ Integer
Returns page number from parameters starting from 1.
27 28 29 |
# File 'lib/adapters/wallaby/active_record/model_pagination_provider.rb', line 27 def page_number [@params[:page].to_i, 1].max end |
#page_size ⇒ Integer
Returns page size from parameters or Wallaby configuration.
22 23 24 |
# File 'lib/adapters/wallaby/active_record/model_pagination_provider.rb', line 22 def page_size @params[:per].to_i end |
#paginatable? ⇒ true, false
Check if collection can be paginated
10 11 12 13 14 |
# File 'lib/adapters/wallaby/active_record/model_pagination_provider.rb', line 10 def paginatable? (@collection.respond_to?(:unscope) && @collection.respond_to?(:count)).tap do |paginatable| Logger.warn "#{@collection} is not paginatable." unless paginatable end end |
#total ⇒ Integer
Returns total count for the collection.
17 18 19 |
# File 'lib/adapters/wallaby/active_record/model_pagination_provider.rb', line 17 def total @tatal ||= @collection.unscope(:offset, :limit).count # rubocop:disable CodeReuse/ActiveRecord end |