class Ckeditor::Paginatable

Simple paginate relation

Attributes

limit_value[R]
offset_value[R]

Public Class Methods

new(scope, options = {}) click to toggle source
# File lib/ckeditor/paginatable.rb, line 8
def initialize(scope, options = {})
  @scope = scope
  @limit_value = (options[:limit] || Ckeditor.default_per_page).to_i
end

Public Instance Methods

all()
Alias for: scoped
current_page() click to toggle source

Current page number

# File lib/ckeditor/paginatable.rb, line 55
def current_page
  offset = (offset_value < 0 ? 0 : offset_value)
  (offset / limit_value) + 1
end
first_page?() click to toggle source

First page of the collection?

# File lib/ckeditor/paginatable.rb, line 35
def first_page?
  current_page == 1
end
last_page?() click to toggle source

Last page of the collection?

# File lib/ckeditor/paginatable.rb, line 40
def last_page?
  current_page >= total_pages
end
next_page() click to toggle source

Next page number in the collection

# File lib/ckeditor/paginatable.rb, line 25
def next_page
  current_page + 1 unless last_page?
end
page(num = 1) click to toggle source
# File lib/ckeditor/paginatable.rb, line 13
def page(num = 1)
  @offset_value = limit_value * ([num.to_i, 1].max - 1)
  self
end
prev_page() click to toggle source

Previous page number in the collection

# File lib/ckeditor/paginatable.rb, line 30
def prev_page
  current_page - 1 unless first_page?
end
scoped() click to toggle source
# File lib/ckeditor/paginatable.rb, line 18
def scoped
  @scope.limit(limit_value).offset(offset_value)
end
Also aliased as: all, to_a
to_a()
Alias for: scoped
total_count() click to toggle source

total item numbers of scope

# File lib/ckeditor/paginatable.rb, line 50
def total_count
  @total_count ||= @scope.count
end
total_pages() click to toggle source

Total number of pages

# File lib/ckeditor/paginatable.rb, line 45
def total_pages
  (total_count.to_f / limit_value).ceil
end