Module: Mongo::Model::Crud::ClassMethods
- Defined in:
- lib/mongo/model/crud.rb
Instance Method Summary collapse
- #build(attributes = {}, options = {}) ⇒ Object
- #create(attributes = {}, options = {}) ⇒ Object
- #create!(attributes = {}, options = {}) ⇒ Object
- #destroy_all(selector = {}, options = {}) ⇒ Object
- #destroy_all!(selector = {}, options = {}) ⇒ Object
Instance Method Details
#build(attributes = {}, options = {}) ⇒ Object
23 24 25 |
# File 'lib/mongo/model/crud.rb', line 23 def build attributes = {}, = {} self.new.set attributes, end |
#create(attributes = {}, options = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/mongo/model/crud.rb', line 27 def create attributes = {}, = {} o = build attributes, o.save o end |
#create!(attributes = {}, options = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/mongo/model/crud.rb', line 33 def create! attributes = {}, = {} o = create attributes raise(Mongo::Error, "can't create #{attributes.inspect}!") if o.new_record? o end |
#destroy_all(selector = {}, options = {}) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/mongo/model/crud.rb', line 39 def destroy_all selector = {}, = {} success = true collection = [:collection] || self.collection each(selector){|o| success = false unless o.destroy} success end |
#destroy_all!(selector = {}, options = {}) ⇒ Object
46 47 48 |
# File 'lib/mongo/model/crud.rb', line 46 def destroy_all! selector = {}, = {} destroy_all(selector, ) || raise(Mongo::Error, "can't destroy #{selector.inspect}!") end |