Module: Devise::Orm::DataMapper::Compatibility::ClassMethods

Defined in:
lib/devise/orm/data_mapper/compatibility.rb

Instance Method Summary collapse

Instance Method Details

#before_validation(*args) ⇒ Object



17
18
19
# File 'lib/devise/orm/data_mapper/compatibility.rb', line 17

def before_validation(*args)
  wrap_hook(:before, :valid?, *args)
end

#wrap_hook(action, method, *args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/devise/orm/data_mapper/compatibility.rb', line 21

def wrap_hook(action, method, *args)
  options = args.extract_options!

  args.each do |callback|
    callback_method = "#{action}_#{method}_#{callback}_callback_wrap".gsub('?', '').to_sym
    send action, method, callback_method
    class_eval <<-METHOD, __FILE__, __LINE__ + 1
      def #{callback_method}
        #{callback} if #{options[:if] || true}
      end
    METHOD
  end
end