Module: MongoMapper::Document::InstanceMethods
- Defined in:
- lib/mongo_mapper/document.rb
Instance Method Summary collapse
-
#_root_document ⇒ Object
Used by embedded docs to find root easily without if/respond_to? stuff.
- #delete ⇒ Object
- #destroy ⇒ Object
- #destroyed? ⇒ Boolean
- #new? ⇒ Boolean
- #reload ⇒ Object
- #save(options = {}) ⇒ Object
- #save!(options = {}) ⇒ Object
Instance Method Details
#_root_document ⇒ Object
Used by embedded docs to find root easily without if/respond_to? stuff. Documents are always root documents.
267 268 269 |
# File 'lib/mongo_mapper/document.rb', line 267 def _root_document self end |
#delete ⇒ Object
242 243 244 245 |
# File 'lib/mongo_mapper/document.rb', line 242 def delete @_destroyed = true self.class.delete(id) unless new? end |
#destroy ⇒ Object
238 239 240 |
# File 'lib/mongo_mapper/document.rb', line 238 def destroy delete end |
#destroyed? ⇒ Boolean
251 252 253 |
# File 'lib/mongo_mapper/document.rb', line 251 def destroyed? @_destroyed == true end |
#reload ⇒ Object
255 256 257 258 259 260 261 262 263 |
# File 'lib/mongo_mapper/document.rb', line 255 def reload if doc = self.class.query(:_id => id).first self.class.associations.each { |name, assoc| send(name).reset if respond_to?(name) } self.attributes = doc self else raise DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection" end end |
#save(options = {}) ⇒ Object
227 228 229 230 231 |
# File 'lib/mongo_mapper/document.rb', line 227 def save(={}) .assert_valid_keys(:validate, :safe) .reverse_merge!(:validate => true) ![:validate] || valid? ? create_or_update() : false end |
#save!(options = {}) ⇒ Object
233 234 235 236 |
# File 'lib/mongo_mapper/document.rb', line 233 def save!(={}) .assert_valid_keys(:safe) save() || raise(DocumentNotValid.new(self)) end |