class Westfield::PageInfo

Attributes

page[R]
per_page[R]

Public Class Methods

new(page: nil, per_page: nil, max_per_page: nil) click to toggle source

max_per_page is a caller-friendly way to set a cap on the maximum number of results. Otherwise, the caller would have to say: “per_page: [(params || 10), 10].min”

# File lib/westfield_paginator/page_info.rb, line 11
def initialize(page: nil, per_page: nil, max_per_page: nil)
  # initialize to the default value on nil or ""
  page = 1 if page.blank?

  # initialize to the default value on nil or ""
  per_page = Westfield::Paginator.config.default_per_page if per_page.blank?

  # initialize to the default value on nil or ""
  max_per_page = Westfield::Paginator.config.max_per_page if max_per_page.blank?

  @per_page = [per_page.to_i, max_per_page].min
  @page = page
end