Module: Devise::Orm::Sequel::Compatibility::ClassMethods
- Defined in:
- lib/devise/orm/sequel/compatibility.rb
Instance Method Summary collapse
- #after_create(*args) ⇒ Object
-
#before_create(*args) ⇒ Object
Hooks for confirmable.
- #before_save(*args) ⇒ Object
- #before_validation(*args) ⇒ Object
-
#create!(*args) ⇒ Object
for some reason devise tests still use create! from the model itself.
- #wrap_hook(action, *args) ⇒ Object
Instance Method Details
#after_create(*args) ⇒ Object
23 24 25 |
# File 'lib/devise/orm/sequel/compatibility.rb', line 23 def after_create (*args) wrap_hook(:after_create, *args) end |
#before_create(*args) ⇒ Object
Hooks for confirmable
19 20 21 |
# File 'lib/devise/orm/sequel/compatibility.rb', line 19 def before_create (*args) wrap_hook(:before_create, *args) end |
#before_save(*args) ⇒ Object
27 28 29 |
# File 'lib/devise/orm/sequel/compatibility.rb', line 27 def before_save (*args) wrap_hook(:before_save, *args) end |
#before_validation(*args) ⇒ Object
31 32 33 |
# File 'lib/devise/orm/sequel/compatibility.rb', line 31 def before_validation (*args) wrap_hook(:before_validation, *args) end |
#create!(*args) ⇒ Object
for some reason devise tests still use create! from the model itself
11 12 13 14 15 16 |
# File 'lib/devise/orm/sequel/compatibility.rb', line 11 def create! (*args) # to_adapter.create!(*args) o = new(*args) raise unless o.save o end |
#wrap_hook(action, *args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/devise/orm/sequel/compatibility.rb', line 35 def wrap_hook (action, *args) = args. callbacks = [] # basically creates a new callback method with _devise_hook suffix # so that the if option can be supported # and then rewrite the original hook method to run the new callbacks # and continue with original hook (it's not pretty) args.each do |callback| callbacks << new_callback = :"#{callback}_devise_hook" class_eval " def \#{new_callback}\n \#{callback} if \#{options[:if] || true}\n end\n METHOD\n end\n\n class_eval <<-METHOD, __FILE__, __LINE__ + 1\n alias_method :orig_\#{action}, :\#{action}\n\n def \#{action}\n \#{callbacks.join(';')}\n\n # original method can still call super\n orig_\#{action}\n end\n METHOD\nend\n", __FILE__, __LINE__ + 1 |