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

Instance Method Details

#_root_documentObject



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

Returns:



25
26
27
# File 'lib/mongo_mapper/plugins/embedded_document.rb', line 25

def destroyed?
  !!_root_document.try(:destroyed?)
end

#new?Boolean

Returns:



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(options={})
  @_new = false
  clear_changes if respond_to?(:clear_changes)
  save_to_collection(options)
end

#save(options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/mongo_mapper/plugins/embedded_document.rb', line 29

def save(options={})
  _root_document.try(:save, options).tap do |result|
    persist(options) 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!(options={})
  valid? || raise(DocumentNotValid.new(self))
  _root_document.try(:save!, options).tap do |result|
    persist(options) if result
  end
end