Module: Mongoid::Interceptable::ClassMethods

Defined in:
lib/mongoid/observers/interceptable.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



44
45
46
47
48
49
# File 'lib/mongoid/observers/interceptable.rb', line 44

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