класс ActiveRecord::Encryption::EncryptedAttributeType
Тип ActiveModel::Type::Value, шифрующий/расшифровывающий строки текста.
Это центральная часть, которая связывает систему шифрования с encrypts объявлениями в классах моделей. Всякий раз, когда вы объявляете атрибут как зашифрованный, он настраивает EncryptedAttributeType для этого атрибута.
Атрибуты
cast_type[R]
scheme[R]
Публичные методы класса
new(scheme:, cast_type: ActiveModel::Type::String.new, previous_type: false, default: nil) Показать исходный код
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 23 def initialize(scheme:, cast_type: ActiveModel::Type::String.new, previous_type: false, default: nil) super() @scheme = scheme @cast_type = cast_type @previous_type = previous_type @default = default end
Параметры
-
:scheme- СхемаSchemeс параметрами шифрования для этого атрибута. -
:cast_type- Тип, который будет использован для сериализации (перед шифрованием) и десериализации (после расшифровки). По умолчанию используетсяActiveModel::Type::String.
Вызывает метод родительского класса
ActiveModel::Type::Value::new Публичные методы экземпляра
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 31 def cast(value) cast_type.cast(value) end
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 51 def changed_in_place?(raw_old_value, new_value) old_value = raw_old_value.nil? ? nil : deserialize(raw_old_value) old_value != new_value end
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 35 def deserialize(value) cast_type.deserialize decrypt(value) end
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 47
def encrypted?(value)
with_context { encryptor.encrypted? value }
end # File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 39
def serialize(value)
if serialize_with_oldest?
serialize_with_oldest(value)
else
serialize_with_current(value)
end
end # File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 61 def support_unencrypted_data? ActiveRecord::Encryption.config.support_unencrypted_data && scheme.support_unencrypted_data? && !previous_type? end
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.