Class: DuffelAPI::Paginator
- Inherits:
-
Object
- Object
- DuffelAPI::Paginator
- Defined in:
- lib/duffel_api/paginator.rb
Instance Method Summary collapse
- #enumerator ⇒ Object
-
#initialize(options = {}) ⇒ Paginator
constructor
A new instance of Paginator.
Constructor Details
#initialize(options = {}) ⇒ Paginator
Returns a new instance of Paginator.
5 6 7 8 |
# File 'lib/duffel_api/paginator.rb', line 5 def initialize( = {}) @service = .fetch(:service) = .fetch(:options) end |
Instance Method Details
#enumerator ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/duffel_api/paginator.rb', line 10 def enumerator response = @service.list() Enumerator.new do |yielder| loop do response.records.each { |item| yielder << item } after_cursor = response.after break if after_cursor.nil? [:params] ||= {} [:params] = [:params].merge(after: after_cursor) response = @service.list() end end.lazy end |