Sha256: 204f13eab7af6aeefd3746c669f9e82c46fbbaec5f78f0fc51c7f16478c6d932

Contents?: true

Size: 611 Bytes

Versions: 8

Compression:

Stored size: 611 Bytes

Contents

# frozen_string_literal: true

module OSA
  class Paginated
    def initialize(value, client)
      @value = value
      @client = client
    end

    def next
      next_page = @value['@odata.nextLink']
      return nil if next_page.nil?
      Paginated.new(@client.get(next_page), @client)
    end

    def all
      value = @value['value'].dup
      next_page = self.next
      until next_page.nil?
        value += next_page['value']
        next_page = next_page.next
      end
      value
    end

    private
      def method_missing(symbol, *args)
        @value.send(symbol, *args)
      end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
osa-0.2.3 lib/osa/util/paginated.rb
osa-0.2.2 lib/osa/util/paginated.rb
osa-0.2.1 lib/osa/util/paginated.rb
osa-0.2.0 lib/osa/util/paginated.rb
osa-0.1.3 lib/osa/util/paginated.rb
osa-0.1.2 lib/osa/util/paginated.rb
osa-0.1.1 lib/osa/util/paginated.rb
osa-0.1.0 lib/osa/util/paginated.rb