Sha256: f2eeb0361a399bd4321aac9aba76341d2908d3f66f6dfae2e99ee3164b593324
Contents?: true
Size: 860 Bytes
Versions: 1
Compression:
Stored size: 860 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] end module InstanceMethods def run_callbacks(callback, &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, &chain) } else chain end end super callback, &block end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongo_mapper-0.9.2 | lib/mongo_mapper/plugins/embedded_callbacks.rb |