diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 6aac3f3..b28f389 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4', '4.0'] + ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4'] steps: - uses: actions/checkout@v2 diff --git a/lib/dothoop/paginated_resource.rb b/lib/dothoop/paginated_resource.rb index 3cf2e8a..4435207 100644 --- a/lib/dothoop/paginated_resource.rb +++ b/lib/dothoop/paginated_resource.rb @@ -25,19 +25,18 @@ def [](index) @collection[index] end - def each(start = 0) + def each(start = 0, &block) # Start off with the first page if we have no idea of anything yet fetch_next_page if total.nil? - return to_enum(:each, start) unless block_given? - Array(@collection[start..-1]).each do |element| - yield(element) - end + return to_enum(:each, start) unless block + + Array(@collection[start..-1]).each(&block) unless last? start = [@collection.size, start].max fetch_next_page - each(start, &Proc.new) + each(start, &block) end self diff --git a/lib/dothoop/version.rb b/lib/dothoop/version.rb index dc52a37..e00d87d 100644 --- a/lib/dothoop/version.rb +++ b/lib/dothoop/version.rb @@ -1,3 +1,3 @@ module Dothoop - VERSION = "0.1.7" + VERSION = "0.1.8" end