Module: Jsonapi::QueryBuilder::Mixins::Paginate

Extended by:
ActiveSupport::Concern
Included in:
BaseQuery
Defined in:
lib/jsonapi/query_builder/mixins/paginate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pagination_detailsObject (readonly)

Returns the value of attribute pagination_details.



22
23
24
# File 'lib/jsonapi/query_builder/mixins/paginate.rb', line 22

def pagination_details
  @pagination_details
end

Instance Method Details

#paginate(collection, page_params = send(:page_params)) ⇒ ActiveRecord::Relation

Paginates the collection and returns the requested page. Also sets the pagination details that can be used for displaying metadata in the Json:Api response.

Parameters:

  • collection (ActiveRecord::Relation)
  • page_params (Object) (defaults to: send(:page_params))

    Optional explicit pagination params

Returns:

  • (ActiveRecord::Relation)

    Paged collection



29
30
31
32
33
# File 'lib/jsonapi/query_builder/mixins/paginate.rb', line 29

def paginate(collection, page_params = send(:page_params))
  records, @pagination_details = self.class._paginator.new(collection).paginate(page_params)

  records
end