Class: Grape::Pagination::Paginator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/grape/pagination/paginator.rb

Constant Summary collapse

TOTAL_HEADER =
'X-Total'.freeze
'Link'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, collection, options = {}) ⇒ Paginator

Returns a new instance of Paginator.



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

def initialize(endpoint, collection, options = {})
  @endpoint   = endpoint
  @collection = collection
  @options    = options
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



9
10
11
# File 'lib/grape/pagination/paginator.rb', line 9

def collection
  @collection
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



8
9
10
# File 'lib/grape/pagination/paginator.rb', line 8

def endpoint
  @endpoint
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/grape/pagination/paginator.rb', line 10

def options
  @options
end

Class Method Details

.paginate(*args) ⇒ Object



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

def self.paginate(*args)
  new(*args).paginate
end

Instance Method Details

#paginateObject



22
23
24
25
# File 'lib/grape/pagination/paginator.rb', line 22

def paginate
  header LINK_HEADER, LinkHeader.new(request.url, page_params).to_rfc5988
  collection.paginate(page_params)
end