Class: Wallaby::ActiveRecord::ModelPaginationProvider

Inherits:
ModelPaginationProvider
  • Object
show all
Defined in:
lib/adapters/wallaby/active_record/model_pagination_provider.rb

Overview

Model pagination provider for Wallaby::ActiveRecord

Instance Method Summary collapse

Instance Method Details

#page_numberInteger

Returns page number from parameters starting from 1.

Returns:

  • (Integer)

    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_sizeInteger

Returns page size from parameters or Wallaby configuration.

Returns:

  • (Integer)

    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

Returns:

  • (true)

    if paginatable

  • (false)

    if not paginatable



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

#totalInteger

Returns total count for the collection.

Returns:

  • (Integer)

    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