Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- devise :database_authenticatable, :registerable, :validatable
- def devise(*modules)
- options = modules.extract_options!.dup
- selected_modules = modules.map(&:to_sym).uniq.sort_by do |s|
- Devise::ALL.index(s) || -1 # follow Devise::ALL order
- end
- devise_modules_hook! do
- include Devise::Models::Authenticatable
- selected_modules.each do |m|
- mod = Devise::Models.const_get(m.to_s.classify)
- if mod.const_defined?("ClassMethods")
- class_mod = mod.const_get("ClassMethods")
- extend class_mod
- if class_mod.respond_to?(:available_configs)
- available_configs = class_mod.available_configs
- available_configs.each do |config|
- next unless options.key?(config)
- send(:"#{config}=", options.delete(config))
- end
- end
- end
- include mod
- end
- self.devise_modules |= selected_modules
- options.each { |key, value| send(:"#{key}=", value) }
- end
- end
- def self.included(base)
- base.extend ClassMethods
- assert_validations_api!(base)
- base.class_eval do
- validates_presence_of :email, if: :email_required?
- validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
- validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
- validates_presence_of :password, if: :password_required?
- validates_confirmation_of :password, if: :password_required?
- validates_length_of :password, within: password_length, allow_blank: true
- end
- end
- # This is from the `devise` method
- if mod.const_defined?("ClassMethods")
- class_mod = mod.const_get("ClassMethods")
- extend class_mod
- # This is the first line of the `self.included(base)` method
- base.extend ClassMethods
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement