Sha256: f302788932413e0fc8f4d412a3fb1eb22d8cc4d9f456da5f51503edbc5f02c48

Contents?: true

Size: 772 Bytes

Versions: 3

Compression:

Stored size: 772 Bytes

Contents

# frozen_string_literal: true

module Trav3
  class Pagination
    attr_reader :travis
    def initialize(travis, result)
      @travis = travis
      @result = result
    end

    # Next page of results
    # @return [Success, RequestError]
    def next
      get(action(:next))
    end

    # First page of results
    # @return [Success, RequestError]
    def first
      get(action(:first))
    end

    # Last page of results
    # @return [Success, RequestError]
    def last
      get(action(:last))
    end

    private # @private

    def action(action)
      dig('@pagination').dig(action.to_s).dig('@href')
    end

    def dig(opt)
      @result.dig(opt)
    end

    def get(path)
      travis.send(:get_path, path.to_s)
    end
    private :travis
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trav3-1.0.0 lib/trav3/pagination.rb
trav3-0.5.1 lib/trav3/pagination.rb
trav3-0.5.0 lib/trav3/pagination.rb