Module: MongoMapper::Document::InstanceMethods
- Defined in:
- lib/mongomapper/document.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #destroy ⇒ Object
- #new? ⇒ Boolean
- #save ⇒ Object
- #save! ⇒ Object
- #update_attributes(attrs = {}) ⇒ Object
Instance Method Details
#collection ⇒ Object
270 271 272 |
# File 'lib/mongomapper/document.rb', line 270 def collection self.class.collection end |
#destroy ⇒ Object
291 292 293 294 295 296 297 |
# File 'lib/mongomapper/document.rb', line 291 def destroy return false if frozen? criteria = FinderOptions.to_mongo_criteria(:_id => id) collection.remove(criteria) unless new? freeze end |
#new? ⇒ Boolean
274 275 276 |
# File 'lib/mongomapper/document.rb', line 274 def new? read_attribute('_id').blank? || using_custom_id? end |
#save ⇒ Object
278 279 280 |
# File 'lib/mongomapper/document.rb', line 278 def save create_or_update end |
#save! ⇒ Object
282 283 284 |
# File 'lib/mongomapper/document.rb', line 282 def save! create_or_update || raise(DocumentNotValid.new(self)) end |
#update_attributes(attrs = {}) ⇒ Object
286 287 288 289 |
# File 'lib/mongomapper/document.rb', line 286 def update_attributes(attrs={}) self.attributes = attrs save end |