Module: MongoMapper::Document::InstanceMethods

Defined in:
lib/mongo_mapper/document.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



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

def collection
  self.class.collection
end

#destroyObject



443
444
445
446
447
# File 'lib/mongo_mapper/document.rb', line 443

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

#new?Boolean

Returns:



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

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

#reloadObject



449
450
451
# File 'lib/mongo_mapper/document.rb', line 449

def reload
  self.class.find(id)
end

#saveObject



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

def save
  valid? ? create_or_update : false
end

#save!Object



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

def save!
  valid? ? create_or_update : raise(DocumentNotValid.new(self))
end