Module: Mongo::Model::Crud
- Defined in:
- lib/mongo/model/crud.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#create_object(collection, options) ⇒ Object
Enhancing Mongo::Object CRUD.
- #delete(options = {}) ⇒ Object
- #delete!(*args) ⇒ Object
- #delete_object(collection, options) ⇒ Object
-
#save(options = {}) ⇒ Object
Model CRUD.
- #save!(*args) ⇒ Object
- #update(doc, options = {}) ⇒ Object
- #update_object(collection, options) ⇒ Object
Instance Method Details
#create_object(collection, options) ⇒ Object
Enhancing Mongo::Object CRUD.
4 5 6 7 8 9 |
# File 'lib/mongo/model/crud.rb', line 4 def create_object collection, with_model_crud_callbacks [:save, :create], do || super collection, true end end |
#delete(options = {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/mongo/model/crud.rb', line 37 def delete = {} with_collection do |collection, | collection.delete self, end end |
#delete!(*args) ⇒ Object
43 44 45 |
# File 'lib/mongo/model/crud.rb', line 43 def delete! *args delete(*args) || raise(Mongo::Error, "can't delete invalid model #{self.errors}!") end |
#delete_object(collection, options) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/mongo/model/crud.rb', line 18 def delete_object collection, with_model_crud_callbacks [:delete], do || super collection, true end end |
#save(options = {}) ⇒ Object
Model CRUD.
27 28 29 30 31 |
# File 'lib/mongo/model/crud.rb', line 27 def save = {} with_collection do |collection, | collection.save self, end end |
#save!(*args) ⇒ Object
33 34 35 |
# File 'lib/mongo/model/crud.rb', line 33 def save! *args save(*args) || raise(Mongo::Error, "can't save invalid model (#{self.errors})!") end |
#update(doc, options = {}) ⇒ Object
47 48 49 50 51 |
# File 'lib/mongo/model/crud.rb', line 47 def update doc, = {} with_collection do |collection, | collection.update({id: id}, doc, ) end end |
#update_object(collection, options) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/mongo/model/crud.rb', line 11 def update_object collection, with_model_crud_callbacks [:save, :update], do || super collection, true end end |