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 6 def initialize(scope, options = {}) @scope = scope @limit_value = (options[:limit] || Ckeditor.default_per_page).to_i end
Public Instance Methods
current_page()
click to toggle source
Current page number
# File lib/ckeditor/paginatable.rb, line 51 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 31 def first_page? current_page == 1 end
last_page?()
click to toggle source
Last page of the collection?
# File lib/ckeditor/paginatable.rb, line 36 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 21 def next_page current_page + 1 unless last_page? end
page(num = 1)
click to toggle source
# File lib/ckeditor/paginatable.rb, line 11 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 26 def prev_page current_page - 1 unless first_page? end
scoped()
click to toggle source
# File lib/ckeditor/paginatable.rb, line 16 def scoped @scope.limit(limit_value).offset(offset_value) end
total_count()
click to toggle source
total item numbers of scope
# File lib/ckeditor/paginatable.rb, line 46 def total_count @total_count ||= @scope.count end
total_pages()
click to toggle source
Total number of pages
# File lib/ckeditor/paginatable.rb, line 41 def total_pages (total_count.to_f / limit_value).ceil end