module Pagination

Constants

DEFAULT_PAGINATION

The order of this hash matters, elements are pulled off the end by calling .pop recursively

NO_COUNT_PAGINATION
VERSION

Public Instance Methods

paginate(pageable_resource, methods = DEFAULT_PAGINATION.dup, params = self.params) click to toggle source

@param pageable_resource [Object] resource to be paged @param methods [Array<Symbol, Lambda>] array of methods to call on the pageable_resource @param params [Object] params object from the controller

# File lib/jbuilder/pagination.rb, line 25
def paginate(pageable_resource, methods = DEFAULT_PAGINATION.dup, params = self.params)
  return pageable_resource if methods.blank?
  key_value_array = methods.pop
  build_pagination(key_value_array, paginate(pageable_resource, methods, params), params)
end
paginate_no_count(pageable_resource, methods = NO_COUNT_PAGINATION.dup, params = self.params) click to toggle source

@param pageable_resource [Object] resource to be paged @param methods [Array<Symbol, Lambda>] array of methods to call on the pageable_resource @param params [Object] params object from the controller

# File lib/jbuilder/pagination.rb, line 18
def paginate_no_count(pageable_resource, methods = NO_COUNT_PAGINATION.dup, params = self.params)
  paginate(pageable_resource, methods, params)
end

Private Instance Methods

build_pagination(key_value_array, pageable_resource, params) click to toggle source
# File lib/jbuilder/pagination.rb, line 33
def build_pagination(key_value_array, pageable_resource, params)
  unless pageable_resource.respond_to?(key_value_array[0])
    raise Errors::UnpageableResourceError, "Resource does not respond to '#{key_value_array[0]}' method!"
  end

  if key_value_array[1].nil?
    return pageable_resource.public_send(key_value_array[0])
  end

  pageable_resource.public_send(key_value_array[0], key_value_array[1].call(params))
end