Class: Api::Paging::RestPaginatorBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/api/paging/rest_paginator_builder.rb

Constant Summary collapse

MAX_LIMIT =
100
DEFAULT_LIMIT =
15

Instance Method Summary collapse

Constructor Details

#initialize(base_query, request, allow_default_page = true, default_limit = DEFAULT_LIMIT) ⇒ RestPaginatorBuilder

Returns a new instance of RestPaginatorBuilder.


9
10
11
12
13
14
15
16
17
18
# File 'lib/api/paging/rest_paginator_builder.rb', line 9

def initialize(base_query, request, allow_default_page=true, default_limit=DEFAULT_LIMIT)
  @base_query = base_query
  @request = request
  @allow_default_page = allow_default_page
  @default_limit = if default_limit < MAX_LIMIT && default_limit > 0
                     default_limit
                   else
                     DEFAULT_LIMIT
                   end
end

Instance Method Details

#index_pager(params) ⇒ Object


20
21
22
23
# File 'lib/api/paging/rest_paginator_builder.rb', line 20

def index_pager(params)
  current_page = current_page_settings(params)
  paged_response_builder(IndexPaginator.new(@base_query, current_page, limit_settings(params)))
end

#time_pager(params, query_time_field = "created_at", data_time_field = query_time_field) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/api/paging/rest_paginator_builder.rb', line 25

def time_pager(params, query_time_field="created_at", data_time_field=query_time_field)
  is_descending, current_time = time_settings(params)
  paged_response_builder(
    TimePaginator.new(
      query_base:       @base_query,
      query_time_field: query_time_field,
      data_time_field:  data_time_field,
      current_time:     current_time,
      is_descending:    is_descending,
      limit:            limit_settings(params)
    )
  )
end