pagination.rb 464 B

123456789101112131415161718192021222324
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class CanPaginate::Pagination
  3. def initialize(params, default: nil, max: nil)
  4. @params = params
  5. @default = default.presence || 100
  6. @max = max.presence || 1000
  7. end
  8. def limit
  9. limit = @params[:per_page] || @params[:limit] || @default
  10. [limit.to_i, @max].min
  11. end
  12. def page
  13. @params[:page]&.to_i || 1
  14. end
  15. def offset
  16. (page - 1) * limit
  17. end
  18. end