added an option to force the deletion of a attachment

This commit is contained in:
Matt Aimonetti 2009-07-29 20:12:35 -07:00
parent beb801d1bd
commit 5270fde0fa
3 changed files with 24 additions and 4 deletions

View file

@ -113,10 +113,21 @@ module CouchRest
end
# DELETE an attachment directly from CouchDB
def delete_attachment doc, name
def delete_attachment(doc, name, force=false)
uri = url_for_attachment(doc, name)
# this needs a rev
JSON.parse(HttpAbstraction.delete(uri))
begin
JSON.parse(HttpAbstraction.delete(uri))
rescue Exception => error
if force
# get over a 409
doc = get(doc['_id'])
uri = url_for_attachment(doc, name)
JSON.parse(HttpAbstraction.delete(uri))
else
error
end
end
end
# Save a document to CouchDB. This will use the <tt>_id</tt> field from