Class: ActiveResource::PaginatedCollection
- Inherits:
-
Collection
- Object
- Collection
- ActiveResource::PaginatedCollection
- Defined in:
- lib/esp/extensions/active_resource/paginated_collection.rb
Instance Method Summary collapse
-
#current_page_number ⇒ String
The current page number of data.
-
#first_page ⇒ PaginatedCollection, self
Returns the first page of results.
-
#first_page! ⇒ PaginatedCollection, self
Updates the existing PaginatedCollection object with the first page of data when not on the first page.
-
#last_page ⇒ PaginatedCollection, self
Returns the last page of results.
-
#last_page! ⇒ PaginatedCollection, self
Updates the existing PaginatedCollection object with the last page of data when not on the last page.
-
#last_page? ⇒ Boolean
Returns whether or not the collection is on the last page.
-
#last_page_number ⇒ String?
The last page number of data.
-
#next_page ⇒ PaginatedCollection, self
Returns the next page of results.
-
#next_page! ⇒ PaginatedCollection, self
Updates the existing PaginatedCollection object with the last page of data when not on the last page.
-
#next_page? ⇒ Boolean
Returns whether or not there is a next page of data in the collection.
-
#next_page_number ⇒ String?
The next page number of data.
-
#page(page_number = nil) ⇒ PaginatedCollection, self
Returns the
page_number
page of data. -
#page!(page_number) ⇒ PaginatedCollection, self
Returns a new PaginatedCollection with the
page_number
page of data when not already on pagepage_number
. -
#previous_page ⇒ PaginatedCollection, self
Returns the previous page of results.
-
#previous_page! ⇒ PaginatedCollection, self
Updates the existing PaginatedCollection object with the previous page of data when not on the first page.
-
#previous_page? ⇒ Boolean
Returns whether or not there is a previous page of data in the collection.
-
#previous_page_number ⇒ String?
The previous page number of data.
Instance Method Details
#current_page_number ⇒ String
The current page number of data.
159 160 161 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 159 def current_page_number (previous_page_number.to_i + 1).to_s end |
#first_page ⇒ PaginatedCollection, self
Returns the first page of results.
Returns self
(and no API call is made) when already on the first page.
35 36 37 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 35 def first_page previous_page? ? updated_collection(from: from, page: { number: 1 }) : self end |
#first_page! ⇒ PaginatedCollection, self
Updates the existing PaginatedCollection object with the first page of data when not on the first page.
46 47 48 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 46 def first_page! first_page.tap { |page| update_self(page) } end |
#last_page ⇒ PaginatedCollection, self
Returns the last page of results.
Returns self
(and no API call is made) when already on the last page.
110 111 112 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 110 def last_page !last_page? ? updated_collection(last_page_params.merge(from: from)) : self end |
#last_page! ⇒ PaginatedCollection, self
Updates the existing PaginatedCollection object with the last page of data when not on the last page.
121 122 123 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 121 def last_page! last_page.tap { |page| update_self(page) } end |
#last_page? ⇒ Boolean
Returns whether or not the collection is on the last page.
201 202 203 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 201 def last_page? last_page_number.nil? end |
#last_page_number ⇒ String?
The last page number of data.
180 181 182 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 180 def last_page_number Hash(last_page_params).fetch('page', {}).fetch('number', nil) end |
#next_page ⇒ PaginatedCollection, self
Returns the next page of results.
Returns self
(and no API call is made) when already on the last page.
85 86 87 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 85 def next_page next_page? ? updated_collection(next_page_params.merge(from: from)) : self end |
#next_page! ⇒ PaginatedCollection, self
Updates the existing PaginatedCollection object with the last page of data when not on the last page.
96 97 98 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 96 def next_page! next_page.tap { |page| update_self(page) } end |
#next_page? ⇒ Boolean
Returns whether or not there is a next page of data in the collection.
194 195 196 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 194 def next_page? !next_page_number.nil? end |
#next_page_number ⇒ String?
The next page number of data.
173 174 175 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 173 def next_page_number Hash(next_page_params).fetch('page', {}).fetch('number', nil) end |
#page(page_number = nil) ⇒ PaginatedCollection, self
Returns the page_number
page of data.
Returns self
when page_number
== #current_page_number
137 138 139 140 141 142 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 137 def page(page_number = nil) fail ArgumentError, "You must supply a page number." unless page_number.present? fail ArgumentError, "Page number cannot be less than 1." if page_number.to_i < 1 fail ArgumentError, "Page number cannot be greater than the last page number." if page_number.to_i > last_page_number.to_i page_number.to_i != current_page_number.to_i ? updated_collection(from: from, page: { number: page_number, size: (next_page_params || previous_page_params)['page']['size'] }) : self end |
#page!(page_number) ⇒ PaginatedCollection, self
Returns a new PaginatedCollection with the page_number
page of data when not already on page page_number
.
152 153 154 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 152 def page!(page_number) page(page_number).tap { |page| update_self(page) } end |
#previous_page ⇒ PaginatedCollection, self
Returns the previous page of results.
Returns self
(and no API call is made) when already on the first page.
60 61 62 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 60 def previous_page previous_page? ? updated_collection(previous_page_params.merge(from: from)) : self end |
#previous_page! ⇒ PaginatedCollection, self
Updates the existing PaginatedCollection object with the previous page of data when not on the first page.
71 72 73 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 71 def previous_page! previous_page.tap { |page| update_self(page) } end |
#previous_page? ⇒ Boolean
Returns whether or not there is a previous page of data in the collection.
187 188 189 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 187 def previous_page? !previous_page_number.nil? end |
#previous_page_number ⇒ String?
The previous page number of data.
166 167 168 |
# File 'lib/esp/extensions/active_resource/paginated_collection.rb', line 166 def previous_page_number Hash(previous_page_params).fetch('page', {}).fetch('number', nil) end |