Module: MarkMapper::Plugins::EmbeddedCallbacks

Extended by:
ActiveSupport::Concern
Included in:
Document, EmbeddedDocument
Defined in:
lib/mark_mapper/plugins/embedded_callbacks.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#run_callbacks(callback, *args, &block) ⇒ Object


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mark_mapper/plugins/embedded_callbacks.rb', line 62

def run_callbacks(callback, *args, &block)
  if self.class.embedded_callbacks_on? and embedded_associations.length > 0
    embedded_docs = embedded_associations.map do |association|
      Array(get_proxy(association).send(:load_target))
    end.flatten(1)

    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
  end

  super callback, *args, &block
end