Class: CursorPaginator::OptionsParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OptionsParser

Returns a new instance of OptionsParser.



9
10
11
12
# File 'lib/cursor_paginator/options_parser.rb', line 9

def initialize(options = {})
  @options = options.deep_dup
  @options[:size] = normalize_page_size
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/cursor_paginator/options_parser.rb', line 7

def options
  @options
end

Instance Method Details

#cursorObject



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

def cursor
  options[:before].presence || options[:after].presence
end

#cursor_directionObject



22
23
24
# File 'lib/cursor_paginator/options_parser.rb', line 22

def cursor_direction
  (after_direction? ? "after" : "before").inquiry
end

#filter_required?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/cursor_paginator/options_parser.rb', line 14

def filter_required?
  cursor.present?
end

#page_sizeObject



26
27
28
# File 'lib/cursor_paginator/options_parser.rb', line 26

def page_size
  @options[:size]
end