module Acfs::Collections::Paginatable

Attributes

current_page[R]
total_count[R]
total_pages[R]

Public Class Methods

operation(_action, **opts, &_block) click to toggle source
# File lib/acfs/collections/paginatable.rb, line 8
def self.operation(_action, **opts, &_block)
  opts[:url]
end

Public Instance Methods

first_page(&block) click to toggle source
# File lib/acfs/collections/paginatable.rb, line 28
def first_page(&block)
  page 'first', &block
end
last_page(&block) click to toggle source
# File lib/acfs/collections/paginatable.rb, line 32
def last_page(&block)
  page 'last', &block
end
next_page(&block) click to toggle source
# File lib/acfs/collections/paginatable.rb, line 20
def next_page(&block)
  page 'next', &block
end
page(rel, &block) click to toggle source
# File lib/acfs/collections/paginatable.rb, line 36
def page(rel, &block)
  return unless relations[rel]

  @resource_class.all nil, url: relations[rel], &block
end
prev_page(&block) click to toggle source
# File lib/acfs/collections/paginatable.rb, line 24
def prev_page(&block)
  page 'prev', &block
end
process_response(response) click to toggle source
# File lib/acfs/collections/paginatable.rb, line 15
def process_response(response)
  setup_params response.request.params if response.request
  setup_headers response.headers
end

Private Instance Methods

relations() click to toggle source
# File lib/acfs/collections/paginatable.rb, line 44
def relations
  @relations ||= {}
end
setup_headers(headers) click to toggle source
# File lib/acfs/collections/paginatable.rb, line 48
def setup_headers(headers)
  if headers['X-Total-Pages']
    @total_pages = Integer(headers['X-Total-Pages'])
  end

  if headers['X-Total-Count']
    @total_count = Integer(headers['X-Total-Count'])
  end

  setup_links headers['Link'] if headers['Link']
end
setup_params(params) click to toggle source
# File lib/acfs/collections/paginatable.rb, line 68
def setup_params(params)
  @current_page = begin
    Integer params.fetch(:page, 1)
  rescue ArgumentError
    params[:page]
  end
end