Module: Mongoid::Callbacks::ClassMethods

Defined in:
lib/mongoid/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#observable(*args) ⇒ Object

Set a custom callback as able to be observed.

Examples:

Set a custom callback as observable.

class Band
  include Mongoid::Document

  define_model_callbacks :notification
  observable :notification
end

Parameters:

  • args (Array<Symbol>)

    The names of the observable callbacks.

Since:

  • 3.0.1



306
307
308
309
310
311
# File 'lib/mongoid/callbacks.rb', line 306

def observable(*args)
  observables = args.flat_map do |name|
    [ :"before_#{name}", :"after_#{name}", :"around_#{name}" ]
  end
  Callbacks.registered_observables.concat(observables).uniq
end