Class: ApiOnlyPagination::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/api_only_pagination/pagination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, params = {}) ⇒ Pagination

Returns a new instance of Pagination.



7
8
9
10
# File 'lib/api_only_pagination/pagination.rb', line 7

def initialize(collection, params = {})
  @collection = collection
  @params = params.merge(count: collection.count)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



5
6
7
# File 'lib/api_only_pagination/pagination.rb', line 5

def collection
  @collection
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/api_only_pagination/pagination.rb', line 5

def params
  @params
end

Instance Method Details

#metadataObject



12
13
14
# File 'lib/api_only_pagination/pagination.rb', line 12

def 
  @metadata ||= ApiOnlyPagination::Paginate.new(params[:page], params[:per_page], params[:count])
end

#resultsObject



16
17
18
19
20
# File 'lib/api_only_pagination/pagination.rb', line 16

def results
  collection
    .limit(.per_page)
    .offset(.offset)
end