Method: Mongoid::Interceptable#run_callbacks

Defined in:
lib/mongoid/interceptable.rb

#run_callbacks(kind, *args, &block) ⇒ Document

Run the callbacks for the document. This overrides active support’s functionality to cascade callbacks to embedded documents that have been flagged as such.

Examples:

Run the callbacks.

run_callbacks :save do
  save!
end

Parameters:

  • kind (Symbol)

    The type of callback to execute.

  • *args (Array)

    Any options.

Returns:

Since:

  • 2.3.0



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/mongoid/interceptable.rb', line 126

def run_callbacks(kind, *args, &block)
  cascadable_children(kind).each do |child|
    # This is returning false for some destroy tests on 4.1.0.beta1,
    # causing them to fail since 4.1.0 expects a block to be passed if the
    # callbacks for the type are empty. If no block is passed then the nil
    # return value gets interpreted as false and halts the chain.
    #
    # @see https://github.com/rails/rails/blob/master/activesupport/lib/active_support/callbacks.rb#L79
    if child.run_callbacks(child_callback_type(kind, child), *args) == false
      return false
    end
  end
  callback_executable?(kind) ? super(kind, *args, &block) : true
end