instance method with_encryption_context

Ruby on Rails 7.2.3

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

with_encryption_context(properties)

Configures a custom encryption context to use when running the provided block of code.

It supports overriding all the properties defined in Context.

Example:

ActiveRecord::Encryption.with_encryption_context(encryptor: ActiveRecord::Encryption::NullEncryptor.new) do
  ...
end

Encryption contexts can be nested.

Parameters

properties req
Source
# File activerecord/lib/active_record/encryption/contexts.rb, line 33
        def with_encryption_context(properties)
          self.custom_contexts ||= []
          self.custom_contexts << default_context.dup
          properties.each do |key, value|
            self.current_custom_context.send("#{key}=", value)
          end

          yield
        ensure
          self.custom_contexts.pop
        end

Defined in activerecord/lib/active_record/encryption/contexts.rb line 33 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Encryption::Contexts

Type at least 2 characters to search.

↑↓ navigate · open · esc close