class ActiveRecord::Encryption::EncryptedAttributeType
ActiveModel::Type::Value, который шифрует и расшифровывает текстовые строки.
Это основной компонент, связывающий систему шифрования с объявлениями encrypts в классах моделей. При объявлении атрибута зашифрованным для него настраивается EncryptedAttributeType.
Атрибуты
Открытые методы класса
# 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? scheme.support_unencrypted_data? && !previous_type? end
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.