Module: Ripple::Callbacks::ClassMethods

Defined in:
lib/ripple/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#after_validation(*args, &block) ⇒ Object

Defines a callback to be run after validations.



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

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

#before_validation(*args, &block) ⇒ Object

Defines a callback to be run before validations.



20
21
22
23
24
25
26
27
# File 'lib/ripple/callbacks.rb', line 20

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