Class: Paginator::Page
- Includes:
- Enumerable
- Defined in:
- lib/vendor/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:.
- #each(&block) ⇒ Object
-
#empty? ⇒ Boolean
Does this page have any items?.
-
#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.
-
#method_missing(meth, *args, &block) ⇒ Object
:nodoc:.
-
#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:
74 75 76 77 78 |
# File 'lib/vendor/paginator.rb', line 74 def initialize(pager, number, select) #:nodoc: @pager, @number = pager, number @offset = (number - 1) * pager.per_page @select = select end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
:nodoc:
133 134 135 136 137 138 139 |
# File 'lib/vendor/paginator.rb', line 133 def method_missing(meth, *args, &block) #:nodoc: if @pager.respond_to?(meth) @pager.__send__(meth, *args, &block) else super end end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
72 73 74 |
# File 'lib/vendor/paginator.rb', line 72 def number @number end |
#pager ⇒ Object (readonly)
Returns the value of attribute pager.
72 73 74 |
# File 'lib/vendor/paginator.rb', line 72 def pager @pager end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
125 126 127 |
# File 'lib/vendor/paginator.rb', line 125 def ==(other) #:nodoc: @pager == other.pager && self.number == other.number end |
#each(&block) ⇒ Object
129 130 131 |
# File 'lib/vendor/paginator.rb', line 129 def each(&block) items.each(&block) end |
#empty? ⇒ Boolean
Does this page have any items?
87 88 89 |
# File 'lib/vendor/paginator.rb', line 87 def empty? items.empty? end |
#first_item_number ⇒ Object
The “item number” of the first item on this page
112 113 114 |
# File 'lib/vendor/paginator.rb', line 112 def first_item_number 1 + @offset end |
#items ⇒ Object
Retrieve the items for this page
-
Caches
82 83 84 |
# File 'lib/vendor/paginator.rb', line 82 def items @items ||= @select.call end |
#last_item_number ⇒ Object
The “item number” of the last item on this page
117 118 119 120 121 122 123 |
# File 'lib/vendor/paginator.rb', line 117 def last_item_number if next? @offset + @pager.per_page else @pager.count end end |
#next ⇒ Object
Get next page (if possible)
107 108 109 |
# File 'lib/vendor/paginator.rb', line 107 def next @pager.page(@number + 1) if next? end |
#next? ⇒ Boolean
Checks to see if there’s a page after this one
102 103 104 |
# File 'lib/vendor/paginator.rb', line 102 def next? @number < @pager.number_of_pages end |
#prev ⇒ Object
Get previous page (if possible)
97 98 99 |
# File 'lib/vendor/paginator.rb', line 97 def prev @pager.page(@number - 1) if prev? end |
#prev? ⇒ Boolean
Checks to see if there’s a page before this one
92 93 94 |
# File 'lib/vendor/paginator.rb', line 92 def prev? @number > 1 end |