Module: Comee::Core::Pagination

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController, Common
Defined in:
app/controllers/concerns/comee/core/pagination.rb

Instance Method Summary collapse

Instance Method Details

#default_per_pageObject



6
7
8
# File 'app/controllers/concerns/comee/core/pagination.rb', line 6

def default_per_page
  25
end

#order_byObject



22
23
24
# File 'app/controllers/concerns/comee/core/pagination.rb', line 22

def order_by
  params.fetch(:order_by, :id)
end

#order_directionObject



26
27
28
# File 'app/controllers/concerns/comee/core/pagination.rb', line 26

def order_direction
  params.fetch(:order_direction, :asc)
end

#page_noObject



10
11
12
# File 'app/controllers/concerns/comee/core/pagination.rb', line 10

def page_no
  params[:page]&.to_i || 1
end

#paginateObject



30
31
32
# File 'app/controllers/concerns/comee/core/pagination.rb', line 30

def paginate
  ->(it) { it.limit(per_page).offset(paginate_offset).order("#{order_by}": order_direction) }
end

#paginate_offsetObject



18
19
20
# File 'app/controllers/concerns/comee/core/pagination.rb', line 18

def paginate_offset
  (page_no - 1) * per_page
end

#per_pageObject



14
15
16
# File 'app/controllers/concerns/comee/core/pagination.rb', line 14

def per_page
  params[:per_page]&.to_i || default_per_page
end