module ActiveMongoid::Associations::DocumentRelation::AutoSave::ClassMethods

Public Instance Methods

autosave_documents(metadata) click to toggle source
# File lib/active_mongoid/associations/document_relation/auto_save.rb, line 13
def autosave_documents(metadata)
  if metadata.autosave?
    save_method = :"autosave_documents_for_#{metadata.name}"
    define_method(save_method) do
      if relation = instance_variable_get("@#{metadata.name}")
        Array(relation).each { |d| d.save if document_changed_for_autosave?(d) }
      end
    end

    after_save save_method
  end
end