Module: NeatPages::Implants::MongoidCriteriaImplant

Defined in:
lib/neat_pages/implants/mongoid_implant.rb

Overview

************************************************************************************* Insert the method paginate in a Mongoid model. This method will be use the limit the number of results returned by a query. *************************************************************************************

Instance Method Summary collapse

Instance Method Details

#paginate(current) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/neat_pages/implants/mongoid_implant.rb', line 6

def paginate(current)
  if current
    current.set_total_items self.count

    raise NeatPages::OutOfBound if current.out_of_bound?

    return self.offset(current.offset).limit(current.limit)
  else
    raise NeatPages::Uninitalized, 'You need to initialize the pagination'
  end
end