Class: Westfield::PageInfo
- Inherits:
-
Object
- Object
- Westfield::PageInfo
- Defined in:
- lib/westfield_paginator/page_info.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
Instance Method Summary collapse
-
#initialize(page: nil, per_page: nil, max_per_page: nil) ⇒ PageInfo
constructor
max_per_page is a caller-friendly way to set a cap on the maximum number of results.
Constructor Details
#initialize(page: nil, per_page: nil, max_per_page: nil) ⇒ PageInfo
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”
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
6 7 8 |
# File 'lib/westfield_paginator/page_info.rb', line 6 def page @page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
6 7 8 |
# File 'lib/westfield_paginator/page_info.rb', line 6 def per_page @per_page end |