Class: Sendmux::Core::CursorPager
- Inherits:
-
Object
- Object
- Sendmux::Core::CursorPager
- Includes:
- Enumerable
- Defined in:
- lib/sendmux/core/pagination.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(fetch_page, cursor_param: :cursor) ⇒ CursorPager
constructor
A new instance of CursorPager.
Constructor Details
#initialize(fetch_page, cursor_param: :cursor) ⇒ CursorPager
Returns a new instance of CursorPager.
8 9 10 11 |
# File 'lib/sendmux/core/pagination.rb', line 8 def initialize(fetch_page, cursor_param: :cursor) @fetch_page = fetch_page @cursor_param = cursor_param end |
Instance Method Details
#each(&block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sendmux/core/pagination.rb', line 13 def each(&block) return enum_for(:each) unless block_given? cursor = nil loop do response = @fetch_page.call(cursor ? { @cursor_param => cursor } : {}) extract_items(response).each(&block) pagination = extract_pagination(response) break unless bool_value?(pagination, 'has_more') cursor = value(pagination, 'next_cursor') break unless cursor end end |