Class: Dolly::BulkDocument

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dolly/bulk_document.rb

Constant Summary collapse

DOC_NAME =
'_bulk_docs'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, ary = []) ⇒ BulkDocument

Returns a new instance of BulkDocument.



12
13
14
15
16
# File 'lib/dolly/bulk_document.rb', line 12

def initialize(connection, ary = [])
  @connection = connection
  @payload = Hash.new
  payload[:docs] = ary
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



7
8
9
# File 'lib/dolly/bulk_document.rb', line 7

def connection
  @connection
end

#errorsObject

Returns the value of attribute errors.



8
9
10
# File 'lib/dolly/bulk_document.rb', line 8

def errors
  @errors
end

#payloadObject (readonly)

Returns the value of attribute payload.



7
8
9
# File 'lib/dolly/bulk_document.rb', line 7

def payload
  @payload
end

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/dolly/bulk_document.rb', line 8

def response
  @response
end

Instance Method Details

#clearObject



34
35
36
37
38
# File 'lib/dolly/bulk_document.rb', line 34

def clear
  self.payload[:docs] = []
  self.response = []
  self.errors = []
end

#deleteObject



29
30
31
32
# File 'lib/dolly/bulk_document.rb', line 29

def delete
  return if docs.empty?
  connection.post DOC_NAME, json_payload(_deleted: true)
end

#docsObject



18
19
20
# File 'lib/dolly/bulk_document.rb', line 18

def docs
  payload[:docs]
end

#saveObject



22
23
24
25
26
27
# File 'lib/dolly/bulk_document.rb', line 22

def save
  return if docs.empty?
  self.response = connection.post(DOC_NAME, docs_payload)
  build_errors
  update_revs
end

#with_errors?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/dolly/bulk_document.rb', line 40

def with_errors?
  response_errors.present?
end