class DHS::Pagination::Base

Constants

DEFAULT_LIMIT

Attributes

data[RW]

Public Class Methods

new(data) click to toggle source
# File lib/dhs/pagination/base.rb, line 14
def initialize(data)
  self.data = data
end
page_to_offset(page, _limit) click to toggle source
# File lib/dhs/pagination/base.rb, line 86
def self.page_to_offset(page, _limit)
  page.to_i
end

Public Instance Methods

count()

as standard in Rails' ActiveRecord count is not summing up, but using the number provided from data source

Alias for: total
current_page() click to toggle source
# File lib/dhs/pagination/base.rb, line 46
def current_page
  # should be implemented in subclass (optional)
end
first_page() click to toggle source
# File lib/dhs/pagination/base.rb, line 50
def first_page
  1
end
last_page() click to toggle source
# File lib/dhs/pagination/base.rb, line 54
def last_page
  total_pages
end
limit() click to toggle source
# File lib/dhs/pagination/base.rb, line 25
def limit
  data._raw.dig(*_record.limit_key(:body)) || DEFAULT_LIMIT
end
limit_value() click to toggle source
# File lib/dhs/pagination/base.rb, line 78
def limit_value
  limit
end
next?() click to toggle source
# File lib/dhs/pagination/base.rb, line 62
def next?
  data._raw[:next].present?
end
next_offset(_step = 1) click to toggle source
# File lib/dhs/pagination/base.rb, line 42
def next_offset(_step = 1)
  raise 'to be implemented in subclass'
end
next_page() click to toggle source
# File lib/dhs/pagination/base.rb, line 74
def next_page
  current_page + 1
end
offset() click to toggle source
# File lib/dhs/pagination/base.rb, line 29
def offset
  data._raw.dig(*_record.pagination_key(:body)) || self.class::DEFAULT_OFFSET
end
Also aliased as: start
pages_left() click to toggle source
# File lib/dhs/pagination/base.rb, line 34
def pages_left
  total_pages - current_page
end
pages_left?() click to toggle source
# File lib/dhs/pagination/base.rb, line 38
def pages_left?
  pages_left > 0
end
parallel?() click to toggle source
# File lib/dhs/pagination/base.rb, line 58
def parallel?
  true
end
prev_page() click to toggle source
# File lib/dhs/pagination/base.rb, line 70
def prev_page
  current_page - 1
end
previous?() click to toggle source
# File lib/dhs/pagination/base.rb, line 66
def previous?
  data._raw[:previous].present?
end
start()
Alias for: offset
total() click to toggle source
# File lib/dhs/pagination/base.rb, line 18
def total
  data._raw.dig(*_record.total_key) || 0
end
Also aliased as: count
total_pages() click to toggle source
# File lib/dhs/pagination/base.rb, line 82
def total_pages
  (total.to_f / limit).ceil
end