Class: ParamsReady::Pagination::CursorBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/params_ready/pagination/cursor.rb

Defined Under Namespace

Classes: Cursor, Literal, Selector

Instance Method Summary collapse

Constructor Details

#initialize(keyset, arel_table, context) ⇒ CursorBuilder

Returns a new instance of CursorBuilder.



7
8
9
10
11
12
# File 'lib/params_ready/pagination/cursor.rb', line 7

def initialize(keyset, arel_table, context)
  @keyset = keyset.freeze
  @arel_table = arel_table
  @context = context
  @select_list = []
end

Instance Method Details

#add(key, column) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/params_ready/pagination/cursor.rb', line 14

def add(key, column)
  attribute = if @keyset.key? key
    Literal.new(key, @keyset[key], column.pk)
  else
    Selector.new(key, column)
  end

  @select_list << attribute
end

#buildObject



24
25
26
27
28
29
# File 'lib/params_ready/pagination/cursor.rb', line 24

def build
  cursor = Cursor.new(@select_list, @arel_table, @context)
  @select_list = nil
  freeze
  cursor
end