added block yields to db.view
This commit is contained in:
parent
b1847cb465
commit
54a0afdf8e
|
@ -16,6 +16,7 @@ module CouchRest
|
||||||
@server = server
|
@server = server
|
||||||
@host = server.uri
|
@host = server.uri
|
||||||
@root = "#{host}/#{name}"
|
@root = "#{host}/#{name}"
|
||||||
|
@streamer = Streamer.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns the database's uri
|
# returns the database's uri
|
||||||
|
@ -48,13 +49,17 @@ module CouchRest
|
||||||
end
|
end
|
||||||
|
|
||||||
# Query a CouchDB view as defined by a <tt>_design</tt> document. Accepts paramaters as described in http://wiki.apache.org/couchdb/HttpViewApi
|
# Query a CouchDB view as defined by a <tt>_design</tt> document. Accepts paramaters as described in http://wiki.apache.org/couchdb/HttpViewApi
|
||||||
def view name, params = {}
|
def view name, params = {}, &block
|
||||||
keys = params.delete(:keys)
|
keys = params.delete(:keys)
|
||||||
url = CouchRest.paramify_url "#{@root}/_view/#{name}", params
|
url = CouchRest.paramify_url "#{@root}/_view/#{name}", params
|
||||||
if keys
|
if keys
|
||||||
CouchRest.post(url, {:keys => keys})
|
CouchRest.post(url, {:keys => keys})
|
||||||
else
|
else
|
||||||
CouchRest.get url
|
if block_given?
|
||||||
|
@streamer.view(name, params, &block)
|
||||||
|
else
|
||||||
|
CouchRest.get url
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,13 @@ describe CouchRest::Database do
|
||||||
rs = @db.view('first/test', :keys => ["another", "wild"])
|
rs = @db.view('first/test', :keys => ["another", "wild"])
|
||||||
rs['rows'].length.should == 2
|
rs['rows'].length.should == 2
|
||||||
end
|
end
|
||||||
|
it "should accept a block" do
|
||||||
|
rows = []
|
||||||
|
rs = @db.view('first/test', :include_docs => true) do |row|
|
||||||
|
rows << row
|
||||||
|
end
|
||||||
|
rows.length.should == 3
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET (document by id) when the doc exists" do
|
describe "GET (document by id) when the doc exists" do
|
||||||
|
|
Loading…
Reference in a new issue