Module: ActiveModel::Validations::Callbacks::ClassMethods

Defined in:
activemodel/lib/active_model/validations/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#after_validation(*args, &block) ⇒ Object


39
40
41
42
43
44
45
46
# File 'activemodel/lib/active_model/validations/callbacks.rb', line 39

def after_validation(*args, &block)
  options = args.extract_options!
  options[:prepend] = true
  options[:if] = Array.wrap(options[:if])
  options[:if] << "!halted"
  options[:if].unshift("self.validation_context == :#{options[:on]}") if options[:on]
  set_callback(:validation, :after, *(args << options), &block)
end

#before_validation(*args, &block) ⇒ Object


30
31
32
33
34
35
36
37
# File 'activemodel/lib/active_model/validations/callbacks.rb', line 30

def before_validation(*args, &block)
  options = args.last
  if options.is_a?(Hash) && options[:on]
    options[:if] = Array.wrap(options[:if])
    options[:if].unshift("self.validation_context == :#{options[:on]}")
  end
  set_callback(:validation, :before, *args, &block)
end