Module: Mongo::Model::Crud::ClassMethods
- Defined in:
- lib/mongo/model/crud.rb
Instance Method Summary collapse
- #build(attributes = {}, options = {}, &block) ⇒ Object
- #create(attributes = {}, options = {}, &block) ⇒ Object
- #create!(attributes = {}, options = {}, &block) ⇒ Object
- #delete_all(selector = {}, options = {}) ⇒ Object
- #delete_all!(selector = {}, options = {}) ⇒ Object
- #update(selector, doc, options = {}) ⇒ Object
Instance Method Details
#build(attributes = {}, options = {}, &block) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/mongo/model/crud.rb', line 70 def build attributes = {}, = {}, &block model = self.new model.set attributes, block.call model if block model end |
#create(attributes = {}, options = {}, &block) ⇒ Object
77 78 79 80 81 |
# File 'lib/mongo/model/crud.rb', line 77 def create attributes = {}, = {}, &block model = build attributes, , &block model.save model end |
#create!(attributes = {}, options = {}, &block) ⇒ Object
83 84 85 86 87 |
# File 'lib/mongo/model/crud.rb', line 83 def create! attributes = {}, = {}, &block model = build attributes, , &block model.save || raise(Mongo::Error, "can't create #{self} #{model.errors.inspect}!") model end |
#delete_all(selector = {}, options = {}) ⇒ Object
89 90 91 92 93 |
# File 'lib/mongo/model/crud.rb', line 89 def delete_all selector = {}, = {} success = true each(selector){|o| success = false unless o.delete } success end |
#delete_all!(selector = {}, options = {}) ⇒ Object
95 96 97 |
# File 'lib/mongo/model/crud.rb', line 95 def delete_all! selector = {}, = {} delete_all(selector, ) || raise(Mongo::Error, "can't delete #{selector.inspect}!") end |
#update(selector, doc, options = {}) ⇒ Object
99 100 101 |
# File 'lib/mongo/model/crud.rb', line 99 def update selector, doc, = {} collection.update selector, doc, end |