Class: ScalarRubyTest::Runtime::Page
- Inherits:
-
Object
- Object
- ScalarRubyTest::Runtime::Page
- Includes:
- Enumerable
- Defined in:
- lib/amritk-scalar-test/runtime.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#next_cursor ⇒ Object
readonly
Returns the value of attribute next_cursor.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #auto_paging_each ⇒ Object
- #each(&block) ⇒ Object
- #each_page ⇒ Object
- #has_next_page? ⇒ Boolean
-
#initialize(items:, response:, next_cursor: nil, fetch_next: nil) ⇒ Page
constructor
A new instance of Page.
- #next_page ⇒ Object
Constructor Details
#initialize(items:, response:, next_cursor: nil, fetch_next: nil) ⇒ Page
Returns a new instance of Page.
45 46 47 48 49 50 |
# File 'lib/amritk-scalar-test/runtime.rb', line 45 def initialize(items:, response:, next_cursor: nil, fetch_next: nil) @items = items @response = response @next_cursor = next_cursor @fetch_next = fetch_next end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
43 44 45 |
# File 'lib/amritk-scalar-test/runtime.rb', line 43 def items @items end |
#next_cursor ⇒ Object (readonly)
Returns the value of attribute next_cursor.
43 44 45 |
# File 'lib/amritk-scalar-test/runtime.rb', line 43 def next_cursor @next_cursor end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
43 44 45 |
# File 'lib/amritk-scalar-test/runtime.rb', line 43 def response @response end |
Instance Method Details
#auto_paging_each ⇒ Object
67 68 69 70 |
# File 'lib/amritk-scalar-test/runtime.rb', line 67 def auto_paging_each return enum_for(:auto_paging_each) unless block_given? each_page { |page| page.each { |item| yield item } } end |
#each(&block) ⇒ Object
52 53 54 55 |
# File 'lib/amritk-scalar-test/runtime.rb', line 52 def each(&block) return enum_for(:each) unless block @items.each(&block) end |
#each_page ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/amritk-scalar-test/runtime.rb', line 57 def each_page return enum_for(:each_page) unless block_given? page = self loop do yield page break unless page.has_next_page? page = page.next_page end end |
#has_next_page? ⇒ Boolean
72 73 74 |
# File 'lib/amritk-scalar-test/runtime.rb', line 72 def has_next_page? !@next_cursor.nil? && !@fetch_next.nil? end |
#next_page ⇒ Object
76 77 78 79 |
# File 'lib/amritk-scalar-test/runtime.rb', line 76 def next_page raise RuntimeError, "No next page available" unless has_next_page? @fetch_next.call(@next_cursor) end |