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