Module: Analysand::Writing

Included in:
Database
Defined in:
lib/analysand/writing.rb

Instance Method Summary collapse

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, options = {})
  body = { 'docs' => docs }
  body['all_or_nothing'] = true if options[: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, options = {})
  bulk_docs(docs, credentials, options).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, options = {})
  Response.new _post('_ensure_full_commit', credentials, options, 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, options = {})
  query = options

  Response.new _put(doc_id, credentials, options, 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, options = {})
  put(doc_id, doc, credentials, options).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 put_attachment(loc, io, credentials = nil, options = {})
  query = {}
  headers = {}

  if options[:rev]
    query['rev'] = options[:rev]
  end

  if options[:content_type]
    headers['Content-Type'] = options[:content_type]
  end

  Response.new _put(loc, credentials, query, headers, io.read)
end