Module: MongoMapper::Document::InstanceMethods
- Defined in:
- lib/mongomapper/document.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #collection ⇒ Object
- #destroy ⇒ Object
- #id ⇒ Object
- #new? ⇒ Boolean
- #save ⇒ Object
- #save! ⇒ Object
- #update_attributes(attrs = {}) ⇒ Object
Instance Method Details
#==(other) ⇒ Object
224 225 226 |
# File 'lib/mongomapper/document.rb', line 224 def ==(other) other.is_a?(self.class) && id == other.id end |
#collection ⇒ Object
197 198 199 |
# File 'lib/mongomapper/document.rb', line 197 def collection self.class.collection end |
#destroy ⇒ Object
219 220 221 222 |
# File 'lib/mongomapper/document.rb', line 219 def destroy collection.remove(:_id => id) unless new? freeze end |
#id ⇒ Object
228 229 230 |
# File 'lib/mongomapper/document.rb', line 228 def id read_attribute('_id') end |
#new? ⇒ Boolean
201 202 203 |
# File 'lib/mongomapper/document.rb', line 201 def new? read_attribute('_id').blank? || self.class.find_by_id(id).blank? end |
#save ⇒ Object
205 206 207 |
# File 'lib/mongomapper/document.rb', line 205 def save create_or_update end |
#save! ⇒ Object
209 210 211 |
# File 'lib/mongomapper/document.rb', line 209 def save! create_or_update || raise(DocumentNotValid.new(self)) end |
#update_attributes(attrs = {}) ⇒ Object
213 214 215 216 217 |
# File 'lib/mongomapper/document.rb', line 213 def update_attributes(attrs={}) self.attributes = attrs save self end |