Module: Deli::Pagination

Defined in:
lib/deli/pagination.rb

Defined Under Namespace

Modules: Collection

Instance Method Summary (collapse)

Instance Method Details

- (Object) page(num)



22
23
24
25
26
27
28
29
# File 'lib/deli/pagination.rb', line 22

def page(num)
  rel              = scoped.extending(::Deli::Pagination::Collection)
  pagenum          = [num.nil? ? 1 : num, 1].max
  per_page         = rel.limit_value || ::Deli.configuration.per_page
  rel              = rel.offset((pagenum.to_i - 1) * per_page.to_i)
  rel              = rel.limit(per_page) unless rel.limit_value
  rel
end

- (Object) paginate(options)



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/deli/pagination.rb', line 3

def paginate(options)
  options  = options.dup
  options[:page] = ((options[:offset] || 0) / options[:limit]).ceil if !options[:page] && options[:limit]
  options[:per_page] ||= options[:limit]
  
  pagenum  = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
  per_page = options.delete(:per_page) || self.per_page
  total    = options.delete(:total_entries)
  
  count_options = options.delete(:count)
  options.delete(:page)
  
  rel = limit(per_page.to_i).page(pagenum)
  
  rel = rel.apply_finder_options(options) if options.any?
  rel.total_entries = total.to_i          unless total.blank?
  rel
end