lib/couchrest/mixins/collection.rb in will-couchrest-0.32.1 vs lib/couchrest/mixins/collection.rb in will-couchrest-0.33

- old
+ new

@@ -1,7 +1,16 @@ module CouchRest module Mixins + module PaginatedResults + def amount_pages + @amount_pages ||= 0 + end + def amount_pages=(value) + @amount_pages = value + end + end + module Collection def self.included(base) base.extend(ClassMethods) end @@ -113,11 +122,14 @@ def paginate(options = {}) page, per_page = parse_options(options) results = @database.view(@view_name, pagination_options(page, per_page)) @amount_pages ||= (results['total_rows'].to_f / per_page.to_f).ceil remember_where_we_left_off(results, page) - convert_to_container_array(results) + results = convert_to_container_array(results) + results.extend(PaginatedResults) + results.amount_pages = @amount_pages + results end # See Collection.paginated_each def paginated_each(options = {}, &block) page, per_page = parse_options(options) @@ -179,10 +191,10 @@ def inspect load_target @target.inspect end - def convert_to_container_array(results) + def convert_to_container_array(results) if @container_class.nil? results else results['rows'].collect { |row| @container_class.new(row['doc']) } unless results['rows'].nil? end