Sha256: d9fff69d63312542084fc8a7271ba751aec1edff7fad18636ab7d11d1c8b1ee8
Contents?: true
Size: 871 Bytes
Versions: 3
Compression:
Stored size: 871 Bytes
Contents
# encoding: UTF-8 module MongoMapper module Plugins module EmbeddedCallbacks extend ActiveSupport::Concern included do extend ::ActiveModel::Callbacks define_model_callbacks :save, :create, :update, :destroy, :only => [:before, :after] define_model_callbacks :touch, :only => [:after] end def run_callbacks(callback, *args, &block) embedded_docs = [] embedded_associations.each do |association| embedded_docs += Array(get_proxy(association).send(:load_target)) end block = embedded_docs.inject(block) do |chain, doc| if doc.class.respond_to?("_#{callback}_callbacks") lambda { doc.run_callbacks(callback, *args, &chain) } else chain end end super callback, *args, &block end end end end
Version data entries
3 entries across 3 versions & 1 rubygems