Class: Dolly::BulkDocument
- Inherits:
-
Object
- Object
- Dolly::BulkDocument
- Extended by:
- Forwardable
- Defined in:
- lib/dolly/bulk_document.rb
Constant Summary collapse
- DOC_NAME =
'_bulk_docs'
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #clear ⇒ Object
- #delete ⇒ Object
- #docs ⇒ Object
-
#initialize(connection, ary = []) ⇒ BulkDocument
constructor
A new instance of BulkDocument.
- #save ⇒ Object
- #with_errors? ⇒ Boolean
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
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/dolly/bulk_document.rb', line 7 def connection @connection end |
#errors ⇒ Object
Returns the value of attribute errors.
8 9 10 |
# File 'lib/dolly/bulk_document.rb', line 8 def errors @errors end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/dolly/bulk_document.rb', line 7 def payload @payload end |
#response ⇒ Object
Returns the value of attribute response.
8 9 10 |
# File 'lib/dolly/bulk_document.rb', line 8 def response @response end |
Instance Method Details
#clear ⇒ Object
34 35 36 37 38 |
# File 'lib/dolly/bulk_document.rb', line 34 def clear self.payload[:docs] = [] self.response = [] self.errors = [] end |
#delete ⇒ Object
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 |
#docs ⇒ Object
18 19 20 |
# File 'lib/dolly/bulk_document.rb', line 18 def docs payload[:docs] end |
#save ⇒ Object
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
40 41 42 |
# File 'lib/dolly/bulk_document.rb', line 40 def with_errors? response_errors.present? end |