Sha256: 499bae785ce451da15f76bdc8eb316e97e47202539156a46d02babe0134cc288

Contents?: true

Size: 1.34 KB

Versions: 85

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module Encryption
    module EncryptedFixtures
      def initialize(fixture, model_class)
        @clean_values = {}
        encrypt_fixture_data(fixture, model_class)
        process_preserved_original_columns(fixture, model_class)
        super
      end

      private
        def encrypt_fixture_data(fixture, model_class)
          model_class&.encrypted_attributes&.each do |attribute_name|
            if clean_value = fixture[attribute_name.to_s]
              @clean_values[attribute_name.to_s] = clean_value

              type = model_class.type_for_attribute(attribute_name)
              encrypted_value = type.serialize(clean_value)
              fixture[attribute_name.to_s] = encrypted_value
            end
          end
        end

        def process_preserved_original_columns(fixture, model_class)
          model_class&.encrypted_attributes&.each do |attribute_name|
            if source_attribute_name = model_class.source_attribute_from_preserved_attribute(attribute_name)
              clean_value = @clean_values[source_attribute_name.to_s]
              type = model_class.type_for_attribute(attribute_name)
              encrypted_value = type.serialize(clean_value)
              fixture[attribute_name.to_s] = encrypted_value
            end
          end
        end
    end
  end
end

Version data entries

85 entries across 82 versions & 9 rubygems

Version Path
activerecord-8.0.2 lib/active_record/encryption/encrypted_fixtures.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.8.7/lib/active_record/encryption/encrypted_fixtures.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/encryption/encrypted_fixtures.rb
activerecord-8.0.1 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-8.0.0.1 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.2.2.1 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.1.5.1 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.0.8.7 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-8.0.0 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.2.2 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.1.5 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-8.0.0.rc2 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.2.1.2 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.1.4.2 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.0.8.6 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-8.0.0.rc1 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.2.1.1 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.1.4.1 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-7.0.8.5 lib/active_record/encryption/encrypted_fixtures.rb
activerecord-8.0.0.beta1 lib/active_record/encryption/encrypted_fixtures.rb