Module: MongoMapper::Document::InstanceMethods
- Defined in:
- lib/mongo_mapper/document.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #database ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #lock_version_field ⇒ Object
- #new? ⇒ Boolean
- #reload ⇒ Object
- #save(options = {}) ⇒ Object
- #save! ⇒ Object
Instance Method Details
#collection ⇒ Object
375 376 377 |
# File 'lib/mongo_mapper/document.rb', line 375 def collection self.class.collection end |
#database ⇒ Object
379 380 381 |
# File 'lib/mongo_mapper/document.rb', line 379 def database self.class.database end |
#delete ⇒ Object
409 410 411 |
# File 'lib/mongo_mapper/document.rb', line 409 def delete self.class.delete(id) unless new? end |
#destroy ⇒ Object
405 406 407 |
# File 'lib/mongo_mapper/document.rb', line 405 def destroy self.class.delete(id) unless new? end |
#lock_version_field ⇒ Object
383 384 385 |
# File 'lib/mongo_mapper/document.rb', line 383 def lock_version_field self.class.lock_version_field end |
#new? ⇒ Boolean
387 388 389 |
# File 'lib/mongo_mapper/document.rb', line 387 def new? read_attribute('_id').blank? || using_custom_id? end |
#reload ⇒ Object
413 414 415 416 417 418 |
# File 'lib/mongo_mapper/document.rb', line 413 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
391 392 393 394 395 396 397 398 399 |
# File 'lib/mongo_mapper/document.rb', line 391 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
401 402 403 |
# File 'lib/mongo_mapper/document.rb', line 401 def save! save || raise(DocumentNotValid.new(self)) end |