Class: Teapi::Documents
- Inherits:
-
Object
- Object
- Teapi::Documents
- Defined in:
- lib/teapi/documents.rb
Overview
Manages documents
Class Method Summary collapse
-
.bulk(type, created_or_updated, deleted) ⇒ Object
bulk updates a type.
-
.create(type, doc, meta = nil) ⇒ Object
creates a new document belonging to the given type.
-
.delete(type, id) ⇒ Object
deletes the document, by its id, belonging to the given type.
-
.update(type, doc, meta = nil) ⇒ Object
updates the document belonging to the given type.
Class Method Details
.bulk(type, created_or_updated, deleted) ⇒ Object
bulk updates a type
35 36 37 38 |
# File 'lib/teapi/documents.rb', line 35 def self.bulk(type, created_or_updated, deleted) return if (created_or_updated.nil? || created_or_updated.length == 0) && (deleted.nil? || deleted.length == 0) Teapi.post(:documents, Oj.dump({type: type, deletes: deleted, upserts: created_or_updated}, mode: :compat, time_format: :ruby)) end |
.create(type, doc, meta = nil) ⇒ Object
creates a new document belonging to the given type
8 9 10 11 12 |
# File 'lib/teapi/documents.rb', line 8 def self.create(type, doc, = nil) d = {type: type, doc: doc} d[:meta] = unless .nil? Teapi.post(:documents, Oj.dump(d, mode: :compat, time_format: :ruby)) end |
.delete(type, id) ⇒ Object
deletes the document, by its id, belonging to the given type
27 28 29 |
# File 'lib/teapi/documents.rb', line 27 def self.delete(type, id) Teapi.delete(:documents, Oj.dump({type: type, id: id}, mode: :compat, time_format: :ruby)) end |
.update(type, doc, meta = nil) ⇒ Object
updates the document belonging to the given type
18 19 20 21 22 |
# File 'lib/teapi/documents.rb', line 18 def self.update(type, doc, = nil) d = {type: type, doc: doc} d[:meta] = unless .nil? Teapi.put(:documents, Oj.dump(d, mode: :compat, time_format: :ruby)) end |