Sha256: cd44467e74a0a5595749a812a9a4bd2d3b6549908e762e455a76ebff5dcc7e8a
Contents?: true
Size: 1.2 KB
Versions: 16
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true module JsonApiToolbox module Paginable def pagination_meta(collection_resource) { 'current-page': collection_resource.current_page, 'next-page': collection_resource.next_page, 'prev-page': collection_resource.previous_page, 'total-pages': collection_resource.total_pages, 'total-count': collection_resource.total_entries } end def pagination(collection_resource) { first: 1, last: collection_resource.total_pages, prev: collection_resource.previous_page, next: collection_resource.next_page }.reduce({}, &method(:page_links)) end def page_links(paginations, entry) link, page = entry if page paginations.merge(create_page_link(link, page)) else paginations end end def create_page_link(link, page) link_path = collection_resource_path(page: page, per_page: params[:per_page]) { link => link_path } end def collection_resource_path(options) path_method = "#{controller_name.pluralize.underscore}_path" public_send(path_method, options) end end end
Version data entries
16 entries across 16 versions & 1 rubygems