added amount_pages to a paginated collection
This commit is contained in:
parent
7a124c522b
commit
413a7602e8
17
history.txt
17
history.txt
|
@ -1,3 +1,20 @@
|
||||||
|
== 0.40
|
||||||
|
|
||||||
|
=== Notes
|
||||||
|
|
||||||
|
This release slightly modifies the API and if you were using a previous version of CouchRest,
|
||||||
|
you will need to make the following modifications.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
* Major enhancements
|
||||||
|
|
||||||
|
*
|
||||||
|
|
||||||
|
* Minor enhancements
|
||||||
|
|
||||||
|
* Added #amount_pages to a paginated collection. (Matt Aimonetti)
|
||||||
|
|
||||||
== 0.31
|
== 0.31
|
||||||
|
|
||||||
* Major enhancements
|
* Major enhancements
|
||||||
|
|
|
@ -84,6 +84,8 @@ module CouchRest
|
||||||
DEFAULT_PAGE = 1
|
DEFAULT_PAGE = 1
|
||||||
DEFAULT_PER_PAGE = 30
|
DEFAULT_PER_PAGE = 30
|
||||||
|
|
||||||
|
attr_accessor :amount_pages
|
||||||
|
|
||||||
# Create a new CollectionProxy to represent the specified view. If a
|
# Create a new CollectionProxy to represent the specified view. If a
|
||||||
# container class is specified, the proxy will create an object of the
|
# container class is specified, the proxy will create an object of the
|
||||||
# given type for each row that comes back from the view. If no
|
# given type for each row that comes back from the view. If no
|
||||||
|
@ -111,6 +113,7 @@ module CouchRest
|
||||||
def paginate(options = {})
|
def paginate(options = {})
|
||||||
page, per_page = parse_options(options)
|
page, per_page = parse_options(options)
|
||||||
results = @database.view(@view_name, pagination_options(page, per_page))
|
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)
|
remember_where_we_left_off(results, page)
|
||||||
convert_to_container_array(results)
|
convert_to_container_array(results)
|
||||||
end
|
end
|
||||||
|
|
|
@ -366,6 +366,11 @@ describe "ExtendedDocument views" do
|
||||||
a.should_not be_nil
|
a.should_not be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
it "should have the amount of paginated pages" do
|
||||||
|
articles = Article.by_date :key => Date.today
|
||||||
|
articles.paginate(:per_page => 3)
|
||||||
|
articles.amount_pages.should == 3
|
||||||
|
end
|
||||||
it "should provide a class method to access the collection directly" do
|
it "should provide a class method to access the collection directly" do
|
||||||
articles = Article.collection_proxy_for('Article', 'by_date', :descending => true,
|
articles = Article.collection_proxy_for('Article', 'by_date', :descending => true,
|
||||||
:key => Date.today, :include_docs => true)
|
:key => Date.today, :include_docs => true)
|
||||||
|
|
Loading…
Reference in a new issue