Module: ActiveRecord::Encryption::ExtendedDeterministicQueries::EncryptedQuery

Defined in:
lib/active_record/encryption/extended_deterministic_queries.rb

Overview

When modifying this file run performance tests in activerecord/test/cases/encryption/performance/extended_deterministic_queries_performance_test.rb to make sure performance overhead is acceptable.

Class Method Summary collapse

Class Method Details

.process_arguments(owner, args, check_for_additional_values) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/active_record/encryption/extended_deterministic_queries.rb', line 43

def process_arguments(owner, args, check_for_additional_values)
  return args if owner.deterministic_encrypted_attributes&.empty?

  if args.is_a?(Array) && (options = args.first).is_a?(Hash)
    options = options.transform_keys do |key|
      if key.is_a?(Array)
        key.map(&:to_s)
      else
        key.to_s
      end
    end
    args[0] = options

    owner.deterministic_encrypted_attributes&.each do |attribute_name|
      attribute_name = attribute_name.to_s
      type = owner.type_for_attribute(attribute_name)
      if !type.previous_types.empty? && value = options[attribute_name]
        options[attribute_name] = process_encrypted_query_argument(value, check_for_additional_values, type)
      end
    end
  end

  args
end