Module: Analysand::Writing
- Included in:
- Database
- Defined in:
- lib/analysand/writing.rb
Instance Method Summary collapse
- #bulk_docs(docs, credentials = nil, options = {}) ⇒ Object
- #bulk_docs!(docs, credentials = nil, options = {}) ⇒ Object
- #copy(source, destination, credentials = nil) ⇒ Object
- #delete(doc_id, rev, credentials = nil) ⇒ Object
- #delete!(doc_id, rev, credentials = nil) ⇒ Object
- #ensure_full_commit(credentials = nil, options = {}) ⇒ Object
- #put(doc_id, doc, credentials = nil, options = {}) ⇒ Object
- #put!(doc_id, doc, credentials = nil, options = {}) ⇒ Object
- #put_attachment(loc, io, credentials = nil, options = {}) ⇒ Object
Instance Method Details
#bulk_docs(docs, credentials = nil, options = {}) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/analysand/writing.rb', line 23 def bulk_docs(docs, credentials = nil, = {}) body = { 'docs' => docs } body['all_or_nothing'] = true if [:all_or_nothing] BulkResponse.new _post('_bulk_docs', credentials, {}, json_headers, body.to_json) end |
#bulk_docs!(docs, credentials = nil, options = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/analysand/writing.rb', line 30 def bulk_docs!(docs, credentials = nil, = {}) bulk_docs(docs, credentials, ).tap do |resp| raise bulk_ex(BulkOperationFailed, resp) unless resp.success? end end |
#copy(source, destination, credentials = nil) ⇒ Object
36 37 38 39 40 |
# File 'lib/analysand/writing.rb', line 36 def copy(source, destination, credentials = nil) headers = { 'Destination' => destination } Response.new _copy(source, credentials, {}, headers, nil) end |
#delete(doc_id, rev, credentials = nil) ⇒ Object
57 58 59 60 61 |
# File 'lib/analysand/writing.rb', line 57 def delete(doc_id, rev, credentials = nil) headers = { 'If-Match' => rev } Response.new _delete(doc_id, credentials, {}, headers, nil) end |
#delete!(doc_id, rev, credentials = nil) ⇒ Object
63 64 65 66 67 |
# File 'lib/analysand/writing.rb', line 63 def delete!(doc_id, rev, credentials = nil) delete(doc_id, rev, credentials).tap do |resp| raise ex(DocumentNotDeleted, resp) unless resp.success? end end |
#ensure_full_commit(credentials = nil, options = {}) ⇒ Object
19 20 21 |
# File 'lib/analysand/writing.rb', line 19 def ensure_full_commit(credentials = nil, = {}) Response.new _post('_ensure_full_commit', credentials, , json_headers, {}.to_json) end |
#put(doc_id, doc, credentials = nil, options = {}) ⇒ Object
7 8 9 10 11 |
# File 'lib/analysand/writing.rb', line 7 def put(doc_id, doc, credentials = nil, = {}) query = Response.new _put(doc_id, credentials, , json_headers, doc.to_json) end |
#put!(doc_id, doc, credentials = nil, options = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/analysand/writing.rb', line 13 def put!(doc_id, doc, credentials = nil, = {}) put(doc_id, doc, credentials, ).tap do |resp| raise ex(DocumentNotSaved, resp) unless resp.success? end end |
#put_attachment(loc, io, credentials = nil, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/analysand/writing.rb', line 42 def (loc, io, credentials = nil, = {}) query = {} headers = {} if [:rev] query['rev'] = [:rev] end if [:content_type] headers['Content-Type'] = [:content_type] end Response.new _put(loc, credentials, query, headers, io.read) end |