Module: MongoMapper::Document::InstanceMethods

Defined in:
lib/mongo_mapper/document.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



418
419
420
# File 'lib/mongo_mapper/document.rb', line 418

def collection
  self.class.collection
end

#destroyObject



434
435
436
437
438
# File 'lib/mongo_mapper/document.rb', line 434

def destroy
  return false if frozen?
  self.class.delete(_id) unless new?
  freeze
end

#new?Boolean

Returns:



422
423
424
# File 'lib/mongo_mapper/document.rb', line 422

def new?
  read_attribute('_id').blank? || using_custom_id?
end

#reloadObject



440
441
442
# File 'lib/mongo_mapper/document.rb', line 440

def reload
  self.class.find(_id)
end

#save(perform_validations = true) ⇒ Object



426
427
428
# File 'lib/mongo_mapper/document.rb', line 426

def save(perform_validations=true)
  !perform_validations || valid? ? create_or_update : false
end

#save!Object



430
431
432
# File 'lib/mongo_mapper/document.rb', line 430

def save!
  save || raise(DocumentNotValid.new(self))
end