Module: Grape::CursorPaginateHelper

Extended by:
API::Helpers
Defined in:
lib/grape/cursor_paginate_helper.rb,
lib/grape/cursor_paginate_helper/version.rb

Defined Under Namespace

Modules: DSLMethods

Constant Summary collapse

DEFAULT_PAGE_SIZE =
10
VERSION =
'0.2.0'

Instance Method Summary collapse

Instance Method Details

#cursor_paginate(collection) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/grape/cursor_paginate_helper.rb', line 24

def cursor_paginate(collection)
  page = ActiveRecord::CursorPaginator.new(collection,
                                           **[:per_page, :cursor, :direction].to_h {|k| [k, params[k]] })
  header 'X-Total',             page.total.to_s if params[:with_total]
  header 'X-Previous-Cursor',   page.start_cursor.to_s if page.previous_page?
  header 'X-Next-Cursor',       page.end_cursor.to_s if page.next_page?
  page.records
end