An ActiveModel::Type::Value that encrypts/decrypts strings of text.
This is the central piece that connects the encryption system with encrypts declarations in the model classes. Whenever you declare an attribute as encrypted, it configures an EncryptedAttributeType for that attribute.
Methods
Included Modules
Attributes
| [R] | cast_type | |
| [R] | scheme | 
Class Public methods
new(scheme:, cast_type: ActiveModel::Type::String.new, previous_type: false, default: nil)
Options
- 
:scheme- ASchemewith the encryption properties for this attribute. - 
:cast_type- A type that will be used to serialize (before encrypting) and deserialize (after decrypting).ActiveModel::Type::Stringby default. 
📝 Source code
# 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
              
                🔎 See on GitHub
              
            Instance Public methods
cast(value)
📝 Source code
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 31
      def cast(value)
        cast_type.cast(value)
      end
              
                🔎 See on GitHub
              
            changed_in_place?(raw_old_value, new_value)
📝 Source code
# 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
              
                🔎 See on GitHub
              
            deserialize(value)
📝 Source code
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 35
      def deserialize(value)
        cast_type.deserialize decrypt(value)
      end
              
                🔎 See on GitHub
              
            encrypted?(value)
📝 Source code
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 47
      def encrypted?(value)
        with_context { encryptor.encrypted? value }
      end
              
                🔎 See on GitHub
              
            serialize(value)
📝 Source code
# 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
              
                🔎 See on GitHub
              
            support_unencrypted_data?()
📝 Source code
# 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
              
                🔎 See on GitHub