Module: MongoMapper::Plugins::EmbeddedDocument
- Extended by:
- ActiveSupport::Concern
- Included in:
- EmbeddedDocument
- Defined in:
- lib/mongo_mapper/plugins/embedded_document.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #_root_document ⇒ Object
- #destroyed? ⇒ Boolean
- #new? ⇒ Boolean
- #persist(options = {}) ⇒ Object
- #save(options = {}) ⇒ Object
- #save!(options = {}) ⇒ Object
Instance Method Details
#_root_document ⇒ Object
48 49 50 |
# File 'lib/mongo_mapper/plugins/embedded_document.rb', line 48 def _root_document @_root_document ||= _parent_document.try(:_root_document) end |
#destroyed? ⇒ Boolean
25 26 27 |
# File 'lib/mongo_mapper/plugins/embedded_document.rb', line 25 def destroyed? !!_root_document.try(:destroyed?) end |
#new? ⇒ Boolean
21 22 23 |
# File 'lib/mongo_mapper/plugins/embedded_document.rb', line 21 def new? _root_document.try(:new?) || @_new end |
#persist(options = {}) ⇒ Object
42 43 44 45 46 |
# File 'lib/mongo_mapper/plugins/embedded_document.rb', line 42 def persist(={}) @_new = false clear_changes if respond_to?(:clear_changes) save_to_collection() end |
#save(options = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/mongo_mapper/plugins/embedded_document.rb', line 29 def save(={}) _root_document.try(:save, ).tap do |result| persist() if result end end |
#save!(options = {}) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/mongo_mapper/plugins/embedded_document.rb', line 35 def save!(={}) valid? || raise(DocumentNotValid.new(self)) _root_document.try(:save!, ).tap do |result| persist() if result end end |