Class: Certynix::Models::Paginator
- Inherits:
-
Object
- Object
- Certynix::Models::Paginator
- Includes:
- Enumerable
- Defined in:
- lib/certynix/models/paginator.rb
Overview
Paginador automático com suporte completo ao módulo Enumerable.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(http:, path:, params: {}) ⇒ Paginator
constructor
A new instance of Paginator.
Constructor Details
#initialize(http:, path:, params: {}) ⇒ Paginator
Returns a new instance of Paginator.
18 19 20 21 22 |
# File 'lib/certynix/models/paginator.rb', line 18 def initialize(http:, path:, params: {}) @http = http @path = path @params = params end |
Instance Method Details
#each ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/certynix/models/paginator.rb', line 24 def each cursor = nil loop do query = cursor ? @params.merge(cursor: cursor) : @params response = @http.get(@path, query) data = response[:data] || [] pagination = response[:pagination] || {} data.each { |item| yield item } break unless pagination[:has_more] cursor = pagination[:next_cursor] break if cursor.nil? || cursor.empty? end end |