Class: Camper::PaginatedResponse
Overview
Wrapper class of paginated response.
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Attributes included from Logging
Instance Method Summary collapse
- #==(other) ⇒ Object
- #auto_paginate(limit = nil, &block) ⇒ Object
- #count ⇒ Object
-
#initialize(array) ⇒ PaginatedResponse
constructor
A new instance of PaginatedResponse.
- #inspect ⇒ Object
- #next_page ⇒ Object
- #next_page? ⇒ Boolean (also: #has_next_page?)
- #parse_headers!(headers) ⇒ Object
Constructor Details
#initialize(array) ⇒ PaginatedResponse
Returns a new instance of PaginatedResponse.
13 14 15 |
# File 'lib/camper/paginated_response.rb', line 13 def initialize(array) @array = array end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
11 12 13 |
# File 'lib/camper/paginated_response.rb', line 11 def client @client end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/camper/paginated_response.rb', line 17 def ==(other) @array == other end |
#auto_paginate(limit = nil, &block) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/camper/paginated_response.rb', line 34 def auto_paginate(limit = nil, &block) limit = count if limit.nil? return lazy_paginate.take(limit).to_a unless block_given? lazy_paginate.take(limit).each(&block) end |
#count ⇒ Object
21 22 23 |
# File 'lib/camper/paginated_response.rb', line 21 def count @pagination_data.total_count end |
#inspect ⇒ Object
25 26 27 |
# File 'lib/camper/paginated_response.rb', line 25 def inspect @array.inspect end |
#next_page ⇒ Object
46 47 48 49 50 |
# File 'lib/camper/paginated_response.rb', line 46 def next_page return nil if @client.nil? || !has_next_page? @client.get(@pagination_data.next, override_path: true) end |
#next_page? ⇒ Boolean Also known as: has_next_page?
41 42 43 |
# File 'lib/camper/paginated_response.rb', line 41 def next_page? !(@pagination_data.nil? || @pagination_data.next.nil?) end |
#parse_headers!(headers) ⇒ Object
29 30 31 32 |
# File 'lib/camper/paginated_response.rb', line 29 def parse_headers!(headers) @pagination_data = PaginationData.new headers logger.debug("Pagination data: #{@pagination_data.inspect}") end |