Class: GoCardlessPro::Paginator
- Inherits:
-
Object
- Object
- GoCardlessPro::Paginator
- Defined in:
- lib/gocardless_pro/paginator.rb
Overview
A class that can take an API LIST query and auto paginate through results
Instance Method Summary collapse
-
#enumerator ⇒ Object
Get a lazy enumerable for listing data from the API.
-
#initialize(options = {}) ⇒ Paginator
constructor
initialize a paginator.
Constructor Details
#initialize(options = {}) ⇒ Paginator
initialize a paginator
8 9 10 11 |
# File 'lib/gocardless_pro/paginator.rb', line 8 def initialize( = {}) @service = .fetch(:service) @options = .fetch(:options) end |
Instance Method Details
#enumerator ⇒ Object
Get a lazy enumerable for listing data from the API
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gocardless_pro/paginator.rb', line 14 def enumerator response = get_initial_response Enumerator.new do |yielder| loop do response.records.each { |item| yielder << item } after_cursor = response.after break if after_cursor.nil? @options[:params] ||= {} @options[:params] = @options[:params].merge(after: after_cursor) response = @service.list(@options.merge(after: after_cursor)) end end.lazy end |