Module: MongoMapper::Document::InstanceMethods
- Defined in:
- lib/mongo_mapper/document.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #database ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #new? ⇒ Boolean
- #reload ⇒ Object
- #save(options = {}) ⇒ Object
- #save! ⇒ Object
Instance Method Details
#collection ⇒ Object
366 367 368 |
# File 'lib/mongo_mapper/document.rb', line 366 def collection self.class.collection end |
#database ⇒ Object
370 371 372 |
# File 'lib/mongo_mapper/document.rb', line 370 def database self.class.database end |
#delete ⇒ Object
396 397 398 |
# File 'lib/mongo_mapper/document.rb', line 396 def delete self.class.delete(id) unless new? end |
#destroy ⇒ Object
392 393 394 |
# File 'lib/mongo_mapper/document.rb', line 392 def destroy self.class.delete(id) unless new? end |
#new? ⇒ Boolean
374 375 376 |
# File 'lib/mongo_mapper/document.rb', line 374 def new? read_attribute('_id').blank? || using_custom_id? end |
#reload ⇒ Object
400 401 402 403 404 405 |
# File 'lib/mongo_mapper/document.rb', line 400 def reload doc = self.class.find(_id) self.class.associations.each { |name, assoc| send(name).reset if respond_to?(name) } self.attributes = doc.attributes self end |
#save(options = {}) ⇒ Object
378 379 380 381 382 383 384 385 386 |
# File 'lib/mongo_mapper/document.rb', line 378 def save(={}) if === false ActiveSupport::Deprecation.warn "save with true/false is deprecated. You should now use :validate => true/false." = {:validate => false} end .reverse_merge!(:validate => true) perform_validations = .delete(:validate) !perform_validations || valid? ? create_or_update() : false end |
#save! ⇒ Object
388 389 390 |
# File 'lib/mongo_mapper/document.rb', line 388 def save! save || raise(DocumentNotValid.new(self)) end |