Class: FoundersToolkit::Auth::Securable::Validations::ProtectedValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- FoundersToolkit::Auth::Securable::Validations::ProtectedValidator
- Defined in:
- lib/founders_toolkit/auth/securable/validations/protected_validator.rb
Defined Under Namespace
Modules: HelperMethods
Instance Method Summary collapse
-
#initialize(options) ⇒ ProtectedValidator
constructor
A new instance of ProtectedValidator.
- #validate_each(record, attribute, _value) ⇒ Object
Constructor Details
#initialize(options) ⇒ ProtectedValidator
Returns a new instance of ProtectedValidator.
5 6 7 8 |
# File 'lib/founders_toolkit/auth/securable/validations/protected_validator.rb', line 5 def initialize() super({ case_sensitive: true }.merge!()) setup! [:class] end |
Instance Method Details
#validate_each(record, attribute, _value) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/founders_toolkit/auth/securable/validations/protected_validator.rb', line 10 def validate_each(record, attribute, _value) return if record.new_record? return unless attribute_changed?(record, attribute) return if authenticate?(record) human_attribute_name = record.class.human_attribute_name(attribute) record.errors.add( :current_password, "Your current password is required to update your #{human_attribute_name}" ) end |