Module: Bpluser::Validatable
- Defined in:
- app/models/bpluser/validatable.rb
Overview
By default, devise requires an email to be unique. I want the email checks but need to remove the uniqueness…
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VALIDATIONS =
All validations used by this module.
[:validates_presence_of, :validates_format_of, :validates_confirmation_of, :validates_length_of].freeze
Class Method Summary collapse
-
.assert_validations_api!(base) ⇒ Object
:nodoc:.
- .included(base) ⇒ Object
- .required_fields(klass) ⇒ Object
Class Method Details
.assert_validations_api!(base) ⇒ Object
:nodoc:
38 39 40 41 42 43 44 45 |
# File 'app/models/bpluser/validatable.rb', line 38 def self.assert_validations_api!(base) #:nodoc: unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) } unless unavailable_validations.empty? raise "Could not use :validatable module since #{base} does not respond " << "to the following methods: #{unavailable_validations.to_sentence}." end end |
.included(base) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/bpluser/validatable.rb', line 23 def self.included(base) base.extend ClassMethods assert_validations_api!(base) base.class_eval do validates_presence_of :email, if: [:email_required?, :email_not_required?] #validates_uniqueness_of :email, allow_blank: true, if: :email_changed? validates_format_of :email, with: email_regexp, allow_blank: true, if: [:email_changed?, :email_not_required?] 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 |
.required_fields(klass) ⇒ Object
19 20 21 |
# File 'app/models/bpluser/validatable.rb', line 19 def self.required_fields(klass) [] end |