lib/neat_pages/implants/mongoid_implant.rb in neat-pages-0.1.7 vs lib/neat_pages/implants/mongoid_implant.rb in neat-pages-1.0.0
- old
+ new
@@ -1,16 +1,18 @@
-module NeatPages::Implants
- module MongoidCriteriaImplant
- def paginate(current)
- if current
- current.set_total_items self.count
+#*************************************************************************************
+# Insert the method paginate in a Mongoid model. This method will be use the limit
+# the number of results returned by a query.
+#*************************************************************************************
+module NeatPages::Implants::MongoidCriteriaImplant
+ def paginate(current)
+ if current
+ current.set_total_items self.count
- raise NeatPages::OutOfBound if current.out_of_bound?
+ raise NeatPages::OutOfBound if current.out_of_bound?
- return self.offset(current.offset).limit(current.limit)
- else
- raise 'You need to initialize the pagination'
- end
+ return self.offset(current.offset).limit(current.limit)
+ else
+ raise NeatPages::Uninitalized, 'You need to initialize the pagination'
end
end
end
Mongoid::Criteria.send :include, NeatPages::Implants::MongoidCriteriaImplant if defined? Mongoid