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

View file

@ -19,9 +19,9 @@ module CouchRest
end
# deletes an attachment directly from couchdb
def delete_attachment(name)
def delete_attachment(name, force=false)
raise ArgumentError, "doc.database required to delete_attachment" unless database
result = database.delete_attachment(self, name)
result = database.delete_attachment(self, name, force)
self['_rev'] = result['rev']
result['ok']
end