akdubya-cushion 0.9.0 → 0.9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cushion.rb +1 -1
- data/lib/cushion/database.rb +11 -0
- data/spec/database_spec.rb +6 -0
- metadata +2 -2
data/lib/cushion.rb
CHANGED
data/lib/cushion/database.rb
CHANGED
@@ -191,6 +191,7 @@ module Cushion
|
|
191
191
|
if delete_all
|
192
192
|
updates = docs.map { |doc|
|
193
193
|
{ '_id' => doc['_id'], '_rev' => doc['_rev'], '_deleted' => true } }
|
194
|
+
use_uuids = false
|
194
195
|
else
|
195
196
|
updates = docs
|
196
197
|
end
|
@@ -205,6 +206,16 @@ module Cushion
|
|
205
206
|
post("_bulk_docs", {:docs => updates}, headers)
|
206
207
|
end
|
207
208
|
|
209
|
+
# Deletes all documents from the database except for design documents.
|
210
|
+
#
|
211
|
+
def clear!(options = {})
|
212
|
+
tv = { :map => "function(doc){emit(doc._rev,null)}" }
|
213
|
+
docs = view(:temp, :funcs => tv)['rows'].map { |row|
|
214
|
+
{ '_id' => row['id'], '_rev' => row['key'], '_deleted' => true }
|
215
|
+
}
|
216
|
+
bulk(docs, options.merge(:use_uuids => false))
|
217
|
+
end
|
218
|
+
|
208
219
|
# Copies the document at +source+ to a new or existing location at +destination+.
|
209
220
|
# Set the +dest_rev+ option to overwrite an existing document. Set the
|
210
221
|
# +headers+ option to pass custom request headers. Example:
|
data/spec/database_spec.rb
CHANGED
@@ -189,6 +189,12 @@ describe "A Cushion database" do
|
|
189
189
|
@db.info["doc_count"].should == count - 2
|
190
190
|
end
|
191
191
|
|
192
|
+
it "should delete all non-design documents with #clear!" do
|
193
|
+
@db.bulk([{"_id" => "abc"},{"_id" => "123"},{"_id" => "_design/foo"}])
|
194
|
+
@db.clear!.length.should == 2
|
195
|
+
@db.info["doc_count"].should == 1
|
196
|
+
end
|
197
|
+
|
192
198
|
describe "with views" do
|
193
199
|
before do
|
194
200
|
@db.store("_id" => "gomer", "name" => "gomer pyle")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: akdubya-cushion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.0
|
4
|
+
version: 0.9.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksander Williams
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|