Module: WillPaginate::ActiveRecord::Pagination

Defined in:
lib/ab_admin/hooks/will_paginate_id_prefetch.rb

Instance Method Summary collapse

Instance Method Details

#paginate(options) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ab_admin/hooks/will_paginate_id_prefetch.rb', line 27

def paginate(options)
  options = options.dup
  page_number = options.fetch(:page) { raise ArgumentError, ':page parameter required' }
  per_page = options.delete(:per_page) || self.per_page
  total = options.delete(:total_entries)
  large = options.delete(:large)

  count_options = options.delete(:count)
  options.delete(:page)

  rel = limit(per_page.to_i).page(page_number)
  rel = rel.apply_finder_options(options) if options.any?
  rel.wp_count_options = count_options if count_options
  rel.total_entries = total.to_i unless total.blank?

  if large
    ids = rel.except(:includes).pluck("#{quoted_table_name}.id")
    new_rel = rel.except(:limit, :offset, :where).where(id: ids)
    new_rel.paginate_limit = rel.limit_value.to_i
    new_rel.paginate_offset = rel.offset_value.to_i
    new_rel.total_entries = rel.total_entries
    new_rel.current_page = rel.current_page
    new_rel
  else
    rel
  end
end