123456789_123456789_123456789_123456789_123456789_

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

Do not use. This module is for internal use only.

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

Class Method Details

.additional_values_for(value, type) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/extended_deterministic_queries.rb', line 87

def additional_values_for(value, type)
  type.previous_types.collect do |additional_type|
    AdditionalValue.new(value, additional_type)
  end
end

.process_arguments(owner, args, check_for_additional_values)

[ GitHub ]

  
# File 'activerecord/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

.process_encrypted_query_argument(value, check_for_additional_values, type) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/extended_deterministic_queries.rb', line 69

def process_encrypted_query_argument(value, check_for_additional_values, type)
  return value if check_for_additional_values && value.is_a?(Array) && value.last.is_a?(AdditionalValue)

  case value
  when String, Array
    list = Array(value)
    list + list.flat_map do |each_value|
      if check_for_additional_values && each_value.is_a?(AdditionalValue)
        each_value
      else
        additional_values_for(each_value, type)
      end
    end
  else
    value
  end
end