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

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

Instance Method Summary collapse

Instance Method Details

#after_create(*args) ⇒ Object



13
14
15
# File 'lib/devise/orm/data_mapper/compatibility.rb', line 13

def after_create(*args)
  wrap_hook(:after, :create, *args)
end

#before_create(*args) ⇒ Object

Hooks for confirmable



9
10
11
# File 'lib/devise/orm/data_mapper/compatibility.rb', line 9

def before_create(*args)
  wrap_hook(:before, :create, *args)
end

#before_save(*args) ⇒ Object



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

def before_save(*args)
  wrap_hook(:before, :save, *args)
end

#before_validation(*args) ⇒ Object



21
22
23
# File 'lib/devise/orm/data_mapper/compatibility.rb', line 21

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

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



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/devise/orm/data_mapper/compatibility.rb', line 25

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

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