lib/active_collection/pagination.rb in active_collection-0.2.4 vs lib/active_collection/pagination.rb in active_collection-0.2.5

- old
+ new

@@ -61,10 +61,23 @@ raise_if_loaded @per_page = per @current_page = pg end + # return a paginated collection if it isn't already paginated. + # returns self if already paginated. + def paginate + paginated?? self : page(1) + end + + # forces pagination of self, raising if already loaded. + # returns current_page if the collection is now paginated + # returns nil if already paginated + def paginate! + paginated?? nil : page!(1) + end + # Helper method that is true when someone tries to fetch a page with a # larger number than the last page. Can be used in combination with flashes # and redirecting. # # loads total_entries if not already loaded. @@ -130,23 +143,9 @@ end # Total number of pages. def total_pages (total_entries / per_page.to_f).ceil - end - - # return a paginated collection if it isn't already paginated. - # returns self if already paginated. - def paginate - paginated?? self : page(current_page || 1) - end - - # forces pagination of self, raising if already loaded. - # returns current_page if the collection is now paginated - # returns nil if already paginated - def paginate! - raise_if_loaded - current_page ? nil : @current_page = 1 end # if the collection has a page parameter def paginated? current_page && current_page > 0