Class: CursorPaginator::Paginator::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cursor_paginator/paginator/base.rb

Direct Known Subclasses

ActiveRecord, Array, Dynamoid

Constant Summary collapse

SORT_DIRECTIONS =
%i[asc desc].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_options: {}, paginator_options: {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
# File 'lib/cursor_paginator/paginator/base.rb', line 9

def initialize(page_options: {}, paginator_options: {})
  @options_parser = OptionsParser.new(page_options)
  @paginator_options = paginator_options.reverse_merge(
    order_key: :id,
    primary_key: :id,
    sort_direction: :desc
  )
end

Instance Attribute Details

#options_parserObject (readonly)

Returns the value of attribute options_parser.



6
7
8
# File 'lib/cursor_paginator/paginator/base.rb', line 6

def options_parser
  @options_parser
end

#paginator_optionsObject (readonly)

Returns the value of attribute paginator_options.



6
7
8
# File 'lib/cursor_paginator/paginator/base.rb', line 6

def paginator_options
  @paginator_options
end

Instance Method Details

#take_records(records, limit) ⇒ Object



18
19
20
# File 'lib/cursor_paginator/paginator/base.rb', line 18

def take_records(records, limit)
  records.take(limit)
end