Sha256: 23c89daa07e892a5574bd51eefc910ae7bf04981525a96abf63d1cf46f684449

Contents?: true

Size: 884 Bytes

Versions: 21

Compression:

Stored size: 884 Bytes

Contents

# frozen_string_literal: true

# :markup: markdown

module ActionText
  module Encryption
    def encrypt
      transaction do
        super
        encrypt_rich_texts if has_encrypted_rich_texts?
      end
    end

    def decrypt
      transaction do
        super
        decrypt_rich_texts if has_encrypted_rich_texts?
      end
    end

    private
      def encrypt_rich_texts
        encryptable_rich_texts.each(&:encrypt)
      end

      def decrypt_rich_texts
        encryptable_rich_texts.each(&:decrypt)
      end

      def has_encrypted_rich_texts?
        encryptable_rich_texts.present?
      end

      def encryptable_rich_texts
        @encryptable_rich_texts ||= self.class.rich_text_association_names
          .filter_map { |attribute_name| send(attribute_name) }
          .find_all { |record| record.is_a?(ActionText::EncryptedRichText) }
      end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
actiontext-8.0.1 lib/action_text/encryption.rb
actiontext-8.0.0.1 lib/action_text/encryption.rb
actiontext-7.2.2.1 lib/action_text/encryption.rb
actiontext-8.0.0 lib/action_text/encryption.rb
actiontext-7.2.2 lib/action_text/encryption.rb
actiontext-8.0.0.rc2 lib/action_text/encryption.rb
actiontext-7.2.1.2 lib/action_text/encryption.rb
actiontext-8.0.0.rc1 lib/action_text/encryption.rb
actiontext-7.2.1.1 lib/action_text/encryption.rb
actiontext-8.0.0.beta1 lib/action_text/encryption.rb
omg-actiontext-8.0.0.alpha9 lib/action_text/encryption.rb
omg-actiontext-8.0.0.alpha8 lib/action_text/encryption.rb
omg-actiontext-8.0.0.alpha7 lib/action_text/encryption.rb
omg-actiontext-8.0.0.alpha4 lib/action_text/encryption.rb
omg-actiontext-8.0.0.alpha3 lib/action_text/encryption.rb
actiontext-7.2.1 lib/action_text/encryption.rb
actiontext-7.2.0 lib/action_text/encryption.rb
actiontext-7.2.0.rc1 lib/action_text/encryption.rb
actiontext-7.2.0.beta3 lib/action_text/encryption.rb
actiontext-7.2.0.beta2 lib/action_text/encryption.rb