Class: Sputnik::Document
- Defined in:
- lib/sputnik/document.rb
Class Method Summary collapse
- .all(database_name, collection_name, params = {}) ⇒ Object
- .create(database_name, collection_name, params) ⇒ Object
-
.delete(database_name, collection_name, document_id) ⇒ Object
TODO: how about a “save” option? I could add it here, but it would be two server hits.
- .find(database_name, collection_name, document_id) ⇒ Object
- .update(database_name, collection_name, document_id, params) ⇒ Object
Instance Method Summary collapse
- #all(params = nil) ⇒ Object
- #create(params = nil) ⇒ Object
- #delete(id = nil) ⇒ Object
- #find(id = nil, params = nil) ⇒ Object
- #update(id = nil, params = nil) ⇒ Object
Methods inherited from Base
Class Method Details
.all(database_name, collection_name, params = {}) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/sputnik/document.rb', line 4 def all(database_name, collection_name, params={}) response = client.get("/databases/#{database_name}/collections/#{collection_name}/documents", params) values = [] response.each do |item| values << Document.new(item) end values end |
.create(database_name, collection_name, params) ⇒ Object
17 18 19 |
# File 'lib/sputnik/document.rb', line 17 def create(database_name, collection_name, params) Document.new(client.post("/databases/#{database_name}/collections/#{collection_name}/documents", params)) end |
.delete(database_name, collection_name, document_id) ⇒ Object
TODO: how about a “save” option? I could add it here, but it would be two server hits
27 28 29 |
# File 'lib/sputnik/document.rb', line 27 def delete(database_name, collection_name, document_id) client.delete("/databases/#{database_name}/collections/#{collection_name}/documents/#{document_id}") end |
.find(database_name, collection_name, document_id) ⇒ Object
13 14 15 |
# File 'lib/sputnik/document.rb', line 13 def find(database_name, collection_name, document_id) Document.new(client.get("/databases/#{database_name}/collections/#{collection_name}/documents/#{document_id}")) end |
.update(database_name, collection_name, document_id, params) ⇒ Object
21 22 23 |
# File 'lib/sputnik/document.rb', line 21 def update(database_name, collection_name, document_id, params) Document.new(client.put("/databases/#{database_name}/collections#{collection_name}/documents/#{document_id}", params)) end |
Instance Method Details
#all(params = nil) ⇒ Object
32 33 34 |
# File 'lib/sputnik/document.rb', line 32 def all(params=nil) Document.all(collection.database.db, collection.name, params || self.to_hash) end |
#create(params = nil) ⇒ Object
40 41 42 |
# File 'lib/sputnik/document.rb', line 40 def create(params=nil) Document.create(collection.database.db, collection.name, params || self.to_hash) end |
#delete(id = nil) ⇒ Object
48 49 50 |
# File 'lib/sputnik/document.rb', line 48 def delete(id=nil) Document.delete(collection.database.db, collection.name, id || self._id) end |