Module: UltraMarathon::Callbacks::ClassMethods

Defined in:
lib/ultra_marathon/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#callbacks(*callback_names) ⇒ Object

Add one or more new callbacks for class E.g.

callbacks :after_save

Defines a class method ‘after_save` which takes an object responding to :call (Proc or lambda) or a symbol to be called in the context of the instance

Also defines ‘invoke_after_save_callbacks` instance method for designating when the callbacks should be invoked



81
82
83
84
85
86
87
88
89
# File 'lib/ultra_marathon/callbacks.rb', line 81

def callbacks(*callback_names)
  new_callbacks = Set.new(callback_names) - _callback_names
  new_callbacks.each do |callback_name|
    add_callbacks_accessor callback_name
    define_callback callback_name
    add_invoke_callback callback_name
  end
  self._callback_names = new_callbacks
end