Module: ActiveMongoid::Associations::DocumentRelation::AutoSave::ClassMethods

Defined in:
lib/active_mongoid/associations/document_relation/auto_save.rb

Instance Method Summary collapse

Instance Method Details

#autosave_documents(metadata) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_mongoid/associations/document_relation/auto_save.rb', line 13

def autosave_documents()
  if .autosave?
    save_method = :"autosave_documents_for_#{.name}"
    define_method(save_method) do
      if relation = instance_variable_get("@#{.name}")
        Array(relation).each { |d| d.save if document_changed_for_autosave?(d) }
      end
    end

    after_save save_method
  end
end