*_ditest and *_digest= are defined as public methods

This commit is contained in:
Akira Matsuda 2020-10-02 13:03:54 +09:00
parent 35a15af7a5
commit 9caf8ddb93
1 changed files with 3 additions and 3 deletions

View File

@ -79,7 +79,7 @@ module ActiveModel
# when there is an error, the message is added to the password attribute instead # when there is an error, the message is added to the password attribute instead
# so that the error message will make sense to the end-user. # so that the error message will make sense to the end-user.
validate do |record| validate do |record|
record.errors.add(attribute, :blank) unless record.send("#{attribute}_digest").present? record.errors.add(attribute, :blank) unless record.public_send("#{attribute}_digest").present?
end end
validates_length_of attribute, maximum: ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED validates_length_of attribute, maximum: ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED
@ -94,11 +94,11 @@ module ActiveModel
define_method("#{attribute}=") do |unencrypted_password| define_method("#{attribute}=") do |unencrypted_password|
if unencrypted_password.nil? if unencrypted_password.nil?
self.send("#{attribute}_digest=", nil) self.public_send("#{attribute}_digest=", nil)
elsif !unencrypted_password.empty? elsif !unencrypted_password.empty?
instance_variable_set("@#{attribute}", unencrypted_password) instance_variable_set("@#{attribute}", unencrypted_password)
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
self.send("#{attribute}_digest=", BCrypt::Password.create(unencrypted_password, cost: cost)) self.public_send("#{attribute}_digest=", BCrypt::Password.create(unencrypted_password, cost: cost))
end end
end end