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