module Pragma::Decorator::Pagination
Pagination
provides support for including pagination metadata in your collection.
It is particularly useful when used in conjunction with {Collection}.
It supports both {github.com/kaminari/kaminari Kaminari} and {github.com/mislav/will_paginate will_paginate}.
@example Including pagination metadata
class ArticlesDecorator < Pragma::Decorator::Base include Pragma::Decorator::Collection include Pragma::Decorator::Pagination end # { # "data": [ # { "...": "..." }, # { "...": "..." }, # { "...": "..." } # ], # "total_entries": 150, # "per_page": 30, # "total_pages": 5, # "previous_page": 2, # "current_page": 3, # "next_page": 4 # } ArticlesDecorator.new(Article.all).to_hash
Public Class Methods
included(klass)
click to toggle source
# File lib/pragma/decorator/pagination.rb, line 95 def self.included(klass) klass.include InstanceMethods klass.class_eval do property :total_entries, exec_context: :decorator property :per_page, exec_context: :decorator property :total_pages, exec_context: :decorator property :previous_page, exec_context: :decorator property :current_page, exec_context: :decorator property :next_page, exec_context: :decorator end end