Class: FinchAPI::SinglePage
- Inherits:
-
Array
- Object
- Array
- FinchAPI::SinglePage
- Includes:
- Type::BasePage
- Defined in:
- lib/finch-api/single_page.rb
Overview
Instance Method Summary collapse
- #auto_paging_each(&blk) ⇒ Object
-
#initialize(client:, req:, headers:, page_data:) ⇒ SinglePage
constructor
private
A new instance of SinglePage.
- #inspect ⇒ String
- #next_page ⇒ FinchAPI::SinglePage
- #next_page? ⇒ Boolean
Methods included from Type::BasePage
Constructor Details
#initialize(client:, req:, headers:, page_data:) ⇒ SinglePage
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of SinglePage.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/finch-api/single_page.rb', line 34 def initialize(client:, req:, headers:, page_data:) super model = req.fetch(:model) case page_data in Array replace(page_data.map { FinchAPI::Type::Converter.coerce(model, _1) }) else end end |
Instance Method Details
#auto_paging_each(&blk) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/finch-api/single_page.rb', line 57 def auto_paging_each(&blk) unless block_given? raise ArgumentError.new("A block must be given to ##{__method__}") end page = self loop do page.each { blk.call(_1) } break unless page.next_page? page = page.next_page end end |
#inspect ⇒ String
70 71 72 |
# File 'lib/finch-api/single_page.rb', line 70 def inspect "#<#{self.class}:0x#{object_id.to_s(16)}>" end |
#next_page ⇒ FinchAPI::SinglePage
52 53 54 |
# File 'lib/finch-api/single_page.rb', line 52 def next_page RuntimeError.new("No more pages available.") end |
#next_page? ⇒ Boolean
46 47 48 |
# File 'lib/finch-api/single_page.rb', line 46 def next_page? false end |