Module: Walruz::More::Pagination::Base

Defined in:
lib/walruz/more/pagination/base.rb

Instance Method Summary collapse

Instance Method Details

#authorized_paginate(actor, action, *args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/walruz/more/pagination/base.rb', line 7

def authorized_paginate(actor, action, *args)
  # All the args are forwarded to WillPaginate, he knows best what to do
  options = args.last if Hash === args.last  

  options[:page] ||= 1
  options[:page] = options[:page].to_i
  offset  = options.delete(:offset).to_i # defaults to 0

  acum = []
  while true
    paginated_collection = self.paginate(*args)
    filter_authorized_items_in_collection(actor, action, acum, paginated_collection, offset)
    if complete_authorized_items_page?(acum, paginated_collection)
      break
    else
      offset = 0
      options[:page] += 1
    end
  end
  paginated_collection.replace(acum)
end