SHARE
TWEET

Untitled

a guest Jun 17th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. devise :database_authenticatable, :registerable, :validatable
  2.      
  3. def devise(*modules)
  4.   options = modules.extract_options!.dup
  5.  
  6.   selected_modules = modules.map(&:to_sym).uniq.sort_by do |s|
  7.     Devise::ALL.index(s) || -1  # follow Devise::ALL order
  8.   end
  9.  
  10.   devise_modules_hook! do
  11.     include Devise::Models::Authenticatable
  12.  
  13.     selected_modules.each do |m|
  14.       mod = Devise::Models.const_get(m.to_s.classify)
  15.  
  16.       if mod.const_defined?("ClassMethods")
  17.         class_mod = mod.const_get("ClassMethods")
  18.         extend class_mod
  19.  
  20.         if class_mod.respond_to?(:available_configs)
  21.           available_configs = class_mod.available_configs
  22.           available_configs.each do |config|
  23.             next unless options.key?(config)
  24.             send(:"#{config}=", options.delete(config))
  25.           end
  26.         end
  27.       end
  28.  
  29.       include mod
  30.     end
  31.  
  32.     self.devise_modules |= selected_modules
  33.     options.each { |key, value| send(:"#{key}=", value) }
  34.   end
  35. end
  36.      
  37. def self.included(base)
  38.   base.extend ClassMethods
  39.   assert_validations_api!(base)
  40.  
  41.   base.class_eval do
  42.     validates_presence_of   :email, if: :email_required?
  43.     validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
  44.     validates_format_of     :email, with: email_regexp, allow_blank: true, if: :email_changed?
  45.  
  46.     validates_presence_of     :password, if: :password_required?
  47.     validates_confirmation_of :password, if: :password_required?
  48.     validates_length_of       :password, within: password_length, allow_blank: true
  49.   end
  50. end
  51.      
  52. # This is from the `devise` method      
  53. if mod.const_defined?("ClassMethods")
  54.   class_mod = mod.const_get("ClassMethods")
  55.   extend class_mod
  56.  
  57. # This is the first line of the `self.included(base)` method
  58. base.extend ClassMethods
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top