Module: MongoMapper::Document::InstanceMethods

Defined in:
lib/mongomapper/document.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



281
282
283
# File 'lib/mongomapper/document.rb', line 281

def collection
  self.class.collection
end

#destroyObject



297
298
299
300
301
302
303
# File 'lib/mongomapper/document.rb', line 297

def destroy
  return false if frozen?

  criteria = FinderOptions.to_mongo_criteria(:_id => id)
  collection.remove(criteria) unless new?
  freeze
end

#new?Boolean

Returns:



285
286
287
# File 'lib/mongomapper/document.rb', line 285

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

#saveObject



289
290
291
# File 'lib/mongomapper/document.rb', line 289

def save
  create_or_update
end

#save!Object



293
294
295
# File 'lib/mongomapper/document.rb', line 293

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