Class: Paginator::Page
- Extended by:
- Forwardable
- Defined in:
- lib/active_scaffold/paginator.rb
Overview
Page object
Retrieves items for a page and provides metadata about the position of the page in the paginator
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#pager ⇒ Object
readonly
Returns the value of attribute pager.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#first_item_number ⇒ Object
The “item number” of the first item on this page.
-
#initialize(pager, number, &select) ⇒ Page
constructor
:nodoc:.
-
#items ⇒ Object
Retrieve the items for this page * Caches.
-
#last_item_number ⇒ Object
The “item number” of the last item on this page.
-
#next ⇒ Object
Get next page (if possible).
-
#next? ⇒ Boolean
Checks to see if there’s a page after this one.
-
#prev ⇒ Object
Get previous page (if possible).
-
#prev? ⇒ Boolean
Checks to see if there’s a page before this one.
Constructor Details
#initialize(pager, number, &select) ⇒ Page
:nodoc:
85 86 87 88 89 90 |
# File 'lib/active_scaffold/paginator.rb', line 85 def initialize(pager, number, &select) # :nodoc: @pager = pager @number = number @offset = (number - 1) * pager.per_page @select = select end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
83 84 85 |
# File 'lib/active_scaffold/paginator.rb', line 83 def number @number end |
#pager ⇒ Object (readonly)
Returns the value of attribute pager.
83 84 85 |
# File 'lib/active_scaffold/paginator.rb', line 83 def pager @pager end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
132 133 134 |
# File 'lib/active_scaffold/paginator.rb', line 132 def ==(other) # :nodoc: @pager == other.pager && number == other.number end |
#first_item_number ⇒ Object
The “item number” of the first item on this page
119 120 121 |
# File 'lib/active_scaffold/paginator.rb', line 119 def first_item_number 1 + @offset end |
#items ⇒ Object
Retrieve the items for this page
-
Caches
94 95 96 |
# File 'lib/active_scaffold/paginator.rb', line 94 def items @items ||= @select.call end |
#last_item_number ⇒ Object
The “item number” of the last item on this page
124 125 126 127 128 129 130 |
# File 'lib/active_scaffold/paginator.rb', line 124 def last_item_number if next? @offset + @pager.per_page else @pager.count end end |
#next ⇒ Object
Get next page (if possible)
114 115 116 |
# File 'lib/active_scaffold/paginator.rb', line 114 def next @pager.page(@number + 1) if next? end |
#next? ⇒ Boolean
Checks to see if there’s a page after this one
109 110 111 |
# File 'lib/active_scaffold/paginator.rb', line 109 def next? @number < @pager.number_of_pages end |
#prev ⇒ Object
Get previous page (if possible)
104 105 106 |
# File 'lib/active_scaffold/paginator.rb', line 104 def prev @pager.page(@number - 1) if prev? end |
#prev? ⇒ Boolean
Checks to see if there’s a page before this one
99 100 101 |
# File 'lib/active_scaffold/paginator.rb', line 99 def prev? @number > 1 end |